A summary of learning about the framework of the backing net Yii (9)--the method of changing the password, flash

Source: Internet
Author: User

① 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.