how to update a field in user table after login

hi i m trying to update the value of the Last_visited in the user table i m currently using this in the site controller

private function lastActive(){


        $user_model = User::model()->findByPk(Yii::app()->user->id);

        $user_model->last_active = date('Y-m-d H:i:s');




            echo 'hello it is not working';


and calling it in the actionLogin function

if($model->validate() && $model->login()){












but it is not working any idea?

If save() returns "false" then there are probably some validation errors:


what type is "last_active" in the database?

date returns a formatted string.

the type of last_active is date time

actually when the model was being saved it required some more attributes which were defined required in the rules so now i m using this to accomplish the issue in the loginForm Model’s login function



			$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days


            User::model()->updateByPk($this->_identity->id,array('last_active'=> new CDbExpression('NOW()')));

			return true;


Since you need to save a single field and don’t need a validation, it’s the best approach.