app\models\Users::save PHP Method

save() public method

public save ( array $options = [] )
$options array
    public function save(array $options = [])
    {
        if (isset($this->password) && strcmp($this->getOriginal('password'), $this->password) !== 0) {
            $this->password = self::makePass($this->password);
        }
        parent::save($options);
    }

Usage Example

示例#1
1
 /**
  * Creates a new Staff model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('admin')) {
         $model = new Staff();
         if (Yii::$app->request->isAjax && $model->load($_POST)) {
             Yii::$app->response->format = 'json';
             return \yii\widgets\ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post())) {
             $user = new Users();
             $user->usertype = 'Staff';
             $user->password = strtolower($model->apellido1 . substr($model->rut, 5, -2));
             $user->email = $model->correo;
             $model->save();
             $user->id_orig = $model->id;
             $user->username = $model->nombre . " " . $model->apellido1;
             $user->save();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
All Usage Examples Of app\models\Users::save