I am using CTimeStampBehaviour for setting create_time and update_time resetting create_time with afterFind() in model, Basically I am setting the format of date to be displayed on the front end. But this does not work as create_time is sent 0000-00-00 00:00:00 on using model's afterFind(). It works fine when I comment afterFind() in model.
I have used this function in my model:
public function behaviors(){
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'create_time',
'updateAttribute' => 'update_time',
'setUpdateOnCreate'=> true,
)
);
}
I have seen the documentation on CTimeStampBehavior class on yii site, it has a reference to afterFind() inheritence but does not suggest how to use it. I am using afterFind() in model like this:
protected function afterFind() {
parent::afterFind();
$this->create_time = Yii::app()->dateFormatter->formatDateTime(
CDateTimeParser::parse(
$this->create_time, 'yyyy-MM-dd hh:mm:ss'
), 'short', 'short'
);
return true;
}
Can anyone suggest why the create_time is being zero filled when using afterFind()?