frontend\models\ChangePasswordForm::change PHP Method

change() public method

Resets password.
public change ( $runValidation = true ) : boolean
return boolean if password was reset.
    public function change($runValidation = true)
    {
        if ($runValidation && !$this->validate()) {
            return false;
        }
        $user = Yii::$app->user->identity;
        $user->password = $this->password;
        return $user->save(false);
    }

Usage Example

 /**
  * 修改密码
  *
  * @return array
  */
 public function actionPassword()
 {
     $model = new ChangePasswordForm();
     if ($model->load(Yii::$app->request->post(), '') && $model->change()) {
         return ['status' => 'success', 'data' => []];
     } else {
         return ['status' => 'fail', 'data' => ['errors' => $model->getFirstErrors()]];
     }
 }