① Ways to change passwords
/** * Change Password * * Public function actionpasswd(){ $userModel= User::model ();if(isset($_post[' User '])){$userInfo=$userModel->find (' Username=:name ',Array(': Name '=>yii::app ()->user->name));$userModel->attributes =$_post[' User '];if($userModel->validate ()) {$password= MD5 ($_post[' User '][' Password1 ']);//The value to be modified is assigned a value of $password if($userModel->UPDATEBYPK ($userInfo->uid,Array(' Password '=$password))){//By UPDATEBYPK This method to modify the password, using this method, the first need to obtain the model, and then you can use this method, the parameters passed as follows the first is the primary key, the second parameter is to modify the field name and the value to be modified to a key value pair. Yii::app ()->user->setflash (' Success ',' Change password succeeded '); } } }//P ($_post); $this->render (' index ',Array(' Usermodel '=$userModel)); }
② uses flash memory this method.
In the controller
Yii::app()->user->setFlash(‘success‘‘修改密码成功‘);
In the view layer, add the following PHP statement
<?php if(Yii::app()->user->hasFlash(‘success‘)){//先要判断对应的闪存是否存在,通过success这个标识符,这个是唯一的。 echo Yii::app()->user->getFlash(‘success‘);//输出对应的信息 ?>
Note that one is set, and then one get and one is has, which is three different methods.
After get, the flash will be erased.
A summary of learning about the framework of the backing net Yii (9)--the method of changing the password, flash