/** * Metodo que faz o processo de cadastro ou atualizacao de dados * @return \yii\web\Response */ protected function saveFormData() { try { if (!$this->model->save()) { throw new Exception(Yii::t('common', 'There was an error saving the record. Details: {error}', ['error' => $this->model->getErrorsToString()])); } $this->getSession()->setFlash('growl', ['type' => 'success', 'title' => Yii::t('common', 'All right!'), 'message' => Yii::t('common', 'Your data has been successfully saved!')]); if (!is_null($this->getRequest()->post('save-and-continue'))) { return $this->refresh(); } else { return $this->redirect(['index']); } } catch (Exception $e) { $errorText = Yii::t('common', 'Oppss... Error!'); $this->getSession()->setFlash('error', '<strong style="font-size: 1.5em">' . $errorText . '</strong>' . $e->getMessage()); return $this->redirect([$this->action->id]); } }
/** * @inheritdoc */ public function beforeSave($insert) { if ($this->isNewRecord) { $this->password = Yii::$app->getSecurity()->generatePasswordHash($this->password); $this->repeatPassword = $this->password; $this->auth_key = Yii::$app->getSecurity()->generateRandomString(70); } else { if (empty($this->password)) { $this->password = $this->currentPassword; $this->repeatPassword = $this->currentPassword; } else { $this->password = Yii::$app->getSecurity()->generatePasswordHash($this->password); $this->repeatPassword = $this->password; } } return parent::beforeSave($insert); }