当前位置: 首页>>代码示例>>PHP>>正文


PHP Person::validate方法代码示例

本文整理汇总了PHP中app\models\Person::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Person::validate方法的具体用法?PHP Person::validate怎么用?PHP Person::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Person的用法示例。


在下文中一共展示了Person::validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Creates a new Student model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $student = new Student();
     $user = new User();
     $person = new Person();
     if (Yii::$app->request->post()) {
         $params = Yii::$app->request->post();
         $person->load($params);
         $user->load($params);
         $user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']);
         $student->load($params);
         if ($person->validate() && $user->validate() && $student->validate()) {
             $person->save(false);
             $user->person_id = $person->id;
             $user->register();
             $student->user_id = $user->id;
             $student->save();
             Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('danger', 'Ocurrió ff un error al guardar. Vuelve a intentar');
             return $this->refresh();
         }
     } else {
         return $this->render('create', ['student' => $student, 'user' => $user, 'person' => $person]);
     }
 }
开发者ID:RomarioLopezC,项目名称:RobotSS,代码行数:32,代码来源:DefaultController.php

示例2: actionCreate

 /**
  * Creates a new Person model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $modelPerson = new Person();
     $modelsHouse = [new House()];
     $modelsRoom = [[new Room()]];
     if ($modelPerson->load(Yii::$app->request->post())) {
         $modelsHouse = Model::createMultiple(House::classname());
         Model::loadMultiple($modelsHouse, Yii::$app->request->post());
         // validate person and houses models
         $valid = $modelPerson->validate();
         $valid = Model::validateMultiple($modelsHouse) && $valid;
         if (isset($_POST['Room'][0][0])) {
             foreach ($_POST['Room'] as $indexHouse => $rooms) {
                 foreach ($rooms as $indexRoom => $room) {
                     $data['Room'] = $room;
                     $modelRoom = new Room();
                     $modelRoom->load($data);
                     $modelsRoom[$indexHouse][$indexRoom] = $modelRoom;
                     $valid = $modelRoom->validate();
                 }
             }
         }
         if ($valid) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelPerson->save(false)) {
                     foreach ($modelsHouse as $indexHouse => $modelHouse) {
                         if ($flag === false) {
                             break;
                         }
                         $modelHouse->person_id = $modelPerson->id;
                         if (!($flag = $modelHouse->save(false))) {
                             break;
                         }
                         if (isset($modelsRoom[$indexHouse]) && is_array($modelsRoom[$indexHouse])) {
                             foreach ($modelsRoom[$indexHouse] as $indexRoom => $modelRoom) {
                                 $modelRoom->house_id = $modelHouse->id;
                                 if (!($flag = $modelRoom->save(false))) {
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelPerson->id]);
                 } else {
                     $transaction->rollBack();
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['modelPerson' => $modelPerson, 'modelsHouse' => empty($modelsHouse) ? [new House()] : $modelsHouse, 'modelsRoom' => empty($modelsRoom) ? [[new Room()]] : $modelsRoom]);
 }
开发者ID:inamjung,项目名称:testupgithup,代码行数:62,代码来源:PersonController.php

示例3: actionPerson

 public function actionPerson()
 {
     $model = new Person();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             // form inputs are valid, do something here
             return;
         }
     }
     return $this->render('person', ['model' => $model]);
 }
开发者ID:unix-admin,项目名称:profitday,代码行数:11,代码来源:SiteController.php

示例4: actionAddFamilyMember

 public function actionAddFamilyMember()
 {
     $this->layout = 'frontend';
     // $searchModel = new SearchPerson();
     $user = new Person();
     $user->scenario = 'add-family';
     // Set Family ID
     $user->family_id = Yii::$app->user->identity->id;
     if ($user->load(Yii::$app->request->post()) && $user->validate()) {
         $user->active = 1;
         if ($user->save()) {
             $user->image = \yii\web\UploadedFile::getInstances($user, 'image');
             $user->uploadPhotos();
             Yii::$app->session->setFlash('success', 'Profile successfully updated');
             return $this->redirect(['/']);
         }
     }
     return $this->render('family-member-form', ['user' => $user]);
 }
开发者ID:jcshep,项目名称:FrontRunner,代码行数:19,代码来源:PersonController.php

示例5: actionCreate

 /**
  * Creates a new Person model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Person();
     $jobModel = new Job();
     if ($jobModel->load(Yii::$app->request->post()) && $jobModel->validate() && $model->load(Yii::$app->request->post()) && $model->validate()) {
         $transaction = $model->getDb()->beginTransaction();
         try {
             if (is_numeric($jobModel->name)) {
                 $jobModel = $jobModel->findOne($jobModel->name);
             } else {
                 $jobModel = new Job();
                 $jobModel->load(Yii::$app->request->post());
                 if (!$jobModel->save(false)) {
                     throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($jobModel->tableName())), 'msj' => print_r($jobModel->getErrors(), true)]), 500);
                 }
             }
             $model->job_id = $jobModel->id;
             if (!$model->save(false)) {
                 throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => print_r($model->getErrors(), true)]), 500);
             }
             $transaction->commit();
         } catch (\Exception $e) {
             $transaction->rollBack();
             throw $e;
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'jobModel' => $jobModel]);
     }
 }
开发者ID:edarkzero,项目名称:mi_taller,代码行数:35,代码来源:PersonController.php


注:本文中的app\models\Person::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。