本文整理汇总了PHP中kartik\form\ActiveForm::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveForm::validate方法的具体用法?PHP ActiveForm::validate怎么用?PHP ActiveForm::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kartik\form\ActiveForm
的用法示例。
在下文中一共展示了ActiveForm::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpdate
/**
* @inheritdoc
* */
public function actionUpdate($id = null)
{
if ($id) {
$modelObject = $this->findRecordModel($id);
} else {
$modelObject = Yii::createObject($this->model);
}
/** @var \nagser\gallery\models\GalleryRecord $modelObject * */
if (\Yii::$app->request->isAjax) {
if ($modelObject->load(\Yii::$app->request->post())) {
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($modelObject);
} else {
return $this->renderAjax('update', ['model' => $modelObject]);
}
} else {
if (Yii::$app->request->isPost) {
$modelObject->file = Yii::$app->gallery->upload($modelObject);
if ($modelObject->upload() and $modelObject->scenario = 'save' and $modelObject->load(\Yii::$app->request->post()) and $modelObject->save()) {
$this->redirect(Url::to(['view', 'id' => $modelObject->id]));
}
}
return $this->render('update', ['model' => $modelObject]);
}
}
示例2: actionCopy
public function actionCopy($id)
{
$model = \Yii::createObject($this->model);
/** @var ThemesRecord $model **/
$model = $model->findRecordModel($id);
if (\Yii::$app->request->isAjax) {
if ($model->load(\Yii::$app->request->post())) {
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
} else {
return $this->renderAjax('copy', ['model' => $model]);
}
} else {
if ($model->load(\Yii::$app->request->post())) {
$model->copy($id);
$this->redirect(Url::to(['view', 'id' => $model->dir]));
}
}
}
示例3: actionCreate
/**
* Create a new User model. If creation is successful, the browser will
* be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
/** @var \amnah\yii2\user\models\User $user */
/** @var \amnah\yii2\user\models\Profile $profile */
/** @var \amnah\yii2\user\models\Role $role */
// AuthAssigment
$permissoes = AuthItem::getListToDropDownList();
$permissoesUser = null;
// set up new user/profile objects
$user = $this->module->model("User", ["scenario" => "register"]);
$profile = $this->module->model("Profile");
$mensagem = "";
//Informa ao usuário mensagens de erro na view
//Permissão do usuário
$authAssignment = new AuthAssignment();
$user->status = 1;
// load post data
$post = Yii::$app->request->post();
if ($user->load($post)) {
// ensure profile data gets loaded
$profile->load($post);
//Inicia a transação:
$transaction = \Yii::$app->db->beginTransaction();
try {
// validate for ajax request
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($user, $profile);
}
// validate for normal request
if ($user->validate() && $profile->validate()) {
$itensInseridos = true;
// perform registration
$role = $this->module->model("Role");
if (!$user->setRegisterAttributes($role::ROLE_USER, $user::STATUS_ACTIVE)->save()) {
$mensagem = "Não foi possível salvar os dados";
$transaction->rollBack();
//desfaz alterações no BD
$itensInseridos = false;
}
if (!$profile->setUser($user->id)->save()) {
$mensagem = "Não foi possível salvar os dados";
$transaction->rollBack();
//desfaz alterações no BD
$itensInseridos = false;
}
$idUser = $user->id;
if (isset($post['AuthAssignment']['item_name']) && !empty($post['AuthAssignment']['item_name'])) {
//Guarda as permissões escolhidas
$roles = $post['AuthAssignment']['item_name'];
foreach ($roles as $role) {
$user->setPermissoes($role, $idUser);
}
}
if ($itensInseridos) {
$transaction->commit();
return $this->redirect(['view', 'id' => $user->id]);
}
}
} catch (\Exception $exception) {
$transaction->rollBack();
$mensagem = "Ocorreu uma falha inesperada ao tentar salvar";
}
}
return $this->render("create", compact("user", "profile", "permissoes", "permissoesUser", "mensagem", "authAssignment"));
}