简体   繁体   中英

I can not update the value in the database Yii?

I can not update the value in the database. Here's the code:

if($user = User::model()->findByAttributes(array('username'=>$verification->username)))
{
    //  Generating 8 random symbols for new password
    $new_password = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyz", 8)), 0, 8);

    //  Transfering password to MD5 hash with salt!
    $new_password = md5('salt'.$new_password);
    $user->password = $new_password;
    if($user->save())
{...

The debugger shows that the value and get it replaced (password), but when you save

if($user->save()) {

Gives false and resets to the most recent line of code:

$this->render('forget');

Questions:

  1. How to find out what happened and why did not update the value?

  2. How to find the error (error code, ...)?

As your last comment, If you have no repeat_password field into your table, add it by hand in your model. (User model). (Actually there is no need to have this field in your table.)

public $repeat_password

Then, define rules for the field. (for example, required and so on...)

To get validation error you can do like below:

CVarDumper::dump($model->getErrors(),56789,true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM