I try to update de last_login_time in my user table, but the time() is always 5h higher than the updatedTime behavior with the function
public function behaviors()
{
return array(
'timestamps' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'create_time',
'updateAttribute' => 'update_time',
'setUpdateOnCreate' => true,
)
);
}
My function to update the last_login_time is very simple:
private function userLogedin()
{
$user = User::model()->findByPk($this->auth->user_id);
$user->last_login_time = date('Y-m-d H:i:s',time());
return $user->save();
}
How can i have the same time than the behaviors one? Is there a way more kindly to create this kind of update?
Thank you very much! I’m a newb with Yii, it’s my first app, so be kind please ^^
CTimestampBehaviorsets the time based on the database server’s local time, as reported byNOW(). Your code sets the time based on the web server’s local time, as reported bytime().The timezone difference between the two servers should account for the 5 hour discrepancy.
If you want to achieve the same effect as
CTimestampBehaviorwith similar syntax as your own code, you will have to useCDbExpression:There’s also an example of the same here.