I followed this article to do automate timestamps in ActiveRecord models. The modified and created values are correctly saved into database. But when I try to retrieve the modified time and created time, something is wrong. Is it a bug?
[_attributes:CActiveRecord:private] => Array
(
[id] => 2956
[title] => saved into database
[created] => 2011-10-26 16:16:30
[modified] => CDbExpression Object
(
[expression] => NOW()
[params] => Array
(
)
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
)
Bug fixed:
$info->hits++;
**$modified = $info->modified;
$info->save(); //This will change modified to Now()
$info->modified = $modified;**
I guess you mean you are trying to retrieve the value of modified in the same request that it is being saved?
In this case, since you (probably) set $this->modified=new CDbExpression(‘NOW()’) in beforeSave event, then this is the value in modified field. In order to get the actual date you will need to retrieve it from the database by using findByPk (or some find method).
Usually this value is not needed in the same request when the model is being saved, but if so you can just use time() I guess.