-1

I was updating the user details using save(). And, i followed the guide of yii framework i.e. Yii2-Guide-Save()

$customer = Customer::findOne(123);
$customer->email = 'james@newexample.com';
$customer->save();

But, it's not updating any value. I'm not getting what is the problem.

When, i'm doing var_dump($users->save()); It's displaying bool(false). $confirmLinkID; value coming.

Here is my controller.

public function actionResend()
{
    $model=new Users(); // User Model

    if ($model->load(Yii::$app->request->post())) {

        $post = Yii::$app->request->post('Users');

        $userDetails = $model->findOne(['email' => $post['email']]);

        // If Account Is Already Activated
        if($userDetails['status'] == 1) {
            Yii::$app->session->setFlash('AccountAlreadyVerified');
            return $this->refresh();
        }

        // If status == 2 
        if($userDetails) { 
            $confirmLinkID=$model->getAuthKey();
            $users = Users::findOne(['email' => $post['email']]);
            $users->auth_key = $confirmLinkID;
            $users->save();
        }
    }
}

Please help.

Nana Partykar
  • 10,175
  • 8
  • 43
  • 73

1 Answers1

2

Try with

 $customer->save(false);

If with the param false the data are saved then you have some problem with validation rules (comment selectively for finding the rule which raises the problem)

otherwise check if you have variable defined in model which can shadow/override the data/column field

Bloodhound
  • 2,720
  • 8
  • 31
  • 66
scaisEdge
  • 124,973
  • 10
  • 73
  • 87
  • After doing `$customer->save(false);` value got updated. Thanks Scais. – Nana Partykar Nov 30 '15 at 11:15
  • Hi @Scais, One question to ask. `$customer->save(false);` is working. It's OK. Will it hamper any security associated issue. Bcoz, `$customer->save();` doesn't work. So, it came in my mind. Can you please explain me (If you are not busy). Thanks. – Nana Partykar Dec 01 '15 at 07:17
  • When using $ customer-> save (false);You do not run the validation rules. This technique is useful when the data contained in the model you are trying to save is in contrast to the validation rules. This technique is then used to determine if the problem is in the phase of validatione or elsewhere. If the problem lies in the rules of validation then you proceed selectively to review the rules in order to find out what is causing the problem of validation. – scaisEdge Dec 01 '15 at 07:30
  • Once identified it comes to understanding why the field does not comply with the rules (if the value of the field is wrong or if the rule to be improved) – scaisEdge Dec 01 '15 at 07:30