Ситуация. Модель User, свойство biorthday типа DATE (в базе), DEFAUL NULL (тоже в базе).
В правилах модели прописал следующее:
Код: Выделить всё
array('bday', 'default', 'setOnEmpty'=>true),//чтобы нули не записывались
array('bday', 'date', 'format'=>'d-m-Y'),//проверка на нужны формат для БД
Код: Выделить всё
public function beforeSave() {
if (parent::beforeSave()) {
if ($this->set_password)
$this->setPassword($this->set_password);
if (empty($this->role))
$this->role = self::ROLE_USER;
$this->set_password = $this->confirm_password = false;
if ($this->bday)
$this->bday = date('Y-m-d', strtotime($this->bday));
return true;
}
else
return false;
}
Код: Выделить всё
public function afterFind() {
if ($this->bday)
$this->bday = date('d-m-Y', strtotime($this->bday));
parent::afterFind();
}
Ребят, объясните пожалуйста =) Наверняка уж чего-то я не допонимаю =)