本文整理汇总了PHP中app\models\Person::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Person::load方法的具体用法?PHP Person::load怎么用?PHP Person::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Person
的用法示例。
在下文中一共展示了Person::load方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
$address = new Address();
if ($model->load(Yii::$app->request->post()) && $address->load(Yii::$app->request->post()) && $model->save()) {
// if (Yii::$app->request->isAjax)
// return $this->renderAjax('view', [
// 'model' => $model,
// ]);
Yii::$app->getSession()->addFlash('success', "Запись \"{$model->fullName}\" успешно добавлена.");
return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
} else {
if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
}
// if (Yii::$app->request->isAjax)
// return $this->renderAjax('_form', [
// 'model' => $model,
// 'address' => $address,
// ]);
if (!Yii::$app->request->isPost) {
$model->load(Yii::$app->request->get());
}
return $this->render('create', ['model' => $model, 'address' => $address]);
}
}
示例2: 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]);
}
}
示例3: 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();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: 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]);
}
示例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();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('alert', ['body' => \Yii::t('app', 'Person {name} was created', ['name' => Html::a($model->getFullName(), Url::toRoute(['view', 'id' => $model->id]))]), 'options' => ['class' => 'alert-success']]);
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例6: 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]);
}
示例7: 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]);
}
示例8: actionGuest
/**
* Show guest register form
* @return mixed
*/
public function actionGuest()
{
$model = new Person();
$model->prs_type = Person::PERSON_TYPE_GUEST;
$model->prs_active = 0;
$oConference = $this->findConferenceModel();
$model->aSectionList = ArrayHelper::map($oConference->sections, 'sec_id', 'sec_title');
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
if ($oConference->cnf_guestlimit > 0 && $oConference->cnf_guestlimit <= $oConference->getGuestcount()) {
return [Html::getInputId($model, 'prs_fam') => ['Превышено максимальное количество гостей']];
}
return ActiveForm::validate($model);
}
if ($oConference->cnf_guestlimit > 0 && $oConference->cnf_guestlimit <= $oConference->getGuestcount()) {
return $this->render('//person/_guest_limit_exeeded', ['oConference' => $oConference, 'model' => $model]);
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->render('//person/ok_guest', ['oConference' => $oConference, 'model' => $model]);
}
return $this->render('//person/_form_guest', ['oConference' => $oConference, 'model' => $model]);
}
示例9: 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]);
}
}