Hi
i wanna let the users to change their ‘username’ any time. (like Twitter website)
i use ‘CDbHttpSession’ to save session in DB.
After update the username in DB, i should update the username in session using the code bellow.
class User extends CActiveRecord
{
...
/**
* This is invoked after the record is saved.
*/
protected function afterSave()
{
parent::afterSave();
if (strcmp(Yii::app()->user->name,$this->username) <> 0) {
// Update session since username has changed
Yii::app()->user->setName($this->username);
}
}
}
But above code is note reliable to update Yii::app()->user->name !
since, some times it doesn’t change Yii::app()->user->name without any error! and i see this situation:
[color="#2E8B57"]in DB: username= new-username[/color]
[color="#FF0000"]in session: name= old-username (Not Updated!)[/color]
could you please help me to find the solution?
[color="#483D8B"]
[b] Note: This problem occurs when i perform AjaxValidation.
and when i turn off the Ajax Validation, i have no problem and every thing works well.
my form is default Gii generated form and also controller is shown in my post below.
[/b][/color]