Change Password With Cformmodel

I am creating a change password functionality , in the change password form I need to use the password field thrice , but with different id , such as oldpassword,newpassword,repeatpassword . it doesn’t match my model structure, thats why I am using Cformmodel . I have created a model which extends the CFormModel and a view and rendering this view in my usercontroller.

==

public function actionChangepassword(){

	$model=new ChangepasswordForm;		


	


	if(isset($_POST['ChangepasswordForm']))


	{


		$model->attributes=$_POST['ChangepasswordForm'];		


		


		if($model->validate())


		{


			 $userid=Yii::app()->user->id;


						


		}


		


	}


	$this->render('changepassword',array(


			'model'=>$model,


	));


}

once this change password form gets submitted , I want to update the user model to modify the password . I am not getting an

idea how I should do it .

Hi

Just do it like that…




if($model->validate())

{

$userid=Yii::app()->user->id;

$user = User::model()->findByPk($userid);


if ($user) {

$user->password = $model->password;

$user->save();

}


}

Hi KonApaz,

It solved my problem, thanks a lot.

Follow this wiki to find best solution -

Change Password with TbActiveForm