本文整理汇总了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]);
}
}
示例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]);
}
示例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]);
}
示例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]);
}
示例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]);
}
}