Answer the question
In order to leave comments, you need to log in
Using Multiple Input, how to update?
Good afternoon. There are a lot of questions from me, but nothing can be done (
There are several models that are filled in in one form - An organization that can have several addresses, phone numbers and to which registration documents must be attached.
The Create method is fine, everything is filled in, everything is attached, everything preserved
public function actionCreate() {
$model = new Organization();
$modelOrganizationAddress = new OrganizationAddress();
$modelOrganizationPhone = new OrganizationPhone();
$license = new UploadLicenseForm();
if ($model->load(Yii::$app->request->post()) &&
$modelOrganizationAddress->load(Yii::$app->request->post()) &&
$modelOrganizationPhone->load(Yii::$app->request->post()) &&
$license->load(Yii::$app->request->post()) &&
$model->save()) {
$modelOrganizationAddress->organization_id = $model->id;
$modelOrganizationPhone->organization_id = $model->id;
$this->saveAddress($modelOrganizationAddress);
$this->savePhone($modelOrganizationPhone);
$license->licenseFiles = UploadedFile::getInstances($license, 'licenseFiles');
if ($license->upload($modelOrganizationLang)) {
Yii::$app->session->setFlash('success', "Организация сохранена");
}
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
'modelOrganizationAddress' => $modelOrganizationAddress,
'modelOrganizationPhone' => $modelOrganizationPhone,
'license' => $license
]);
}
public function actionUpdate($id) {
$model = $this->findModel($id);
$modelOrganizationAddress = OrganizationAddress::find()->where(['organization_id' => $id])->all();
$modelOrganizationPhone = OrganizationPhone::find()->where(['organization_id' => $id])->all();
$license->scenario = 'update-photo-upload';
if ($model->load(Yii::$app->request->post()) &&
$modelOrganizationAddress->load(Yii::$app->request->post()) &&
$modelOrganizationPhone->load(Yii::$app->request->post()) &&
$model->save()) {
// $license->licenseFiles = UploadedFile::getInstances($license, 'licenseFiles');
$modelOrganizationAddress->organization_id = $model->id;
$modelOrganizationPhone->organization_id = $model->id;
$this->saveAddress($modelOrganizationAddress);
$this->savePhone($modelOrganizationPhone);
$license->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
if ($license->upload()) {
Yii::$app->session->setFlash('success', "Организация обновлена");
}
return $this->redirect(['view', 'id' => $model->id]);
}
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->errorSummary($model); ?>
<?=
$form->field($model, 'status')->dropDownList([
'0' => 'Отключена',
'1' => 'Активна',
]);
?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'full_name')->textInput(['maxlength' => true]) ?>
<?php
echo $form->field($modelOrganizationAddress, 'address')->label(HModule::t('organization', 'Address'))->widget(MultipleInput::className(), [
'max' => 4,
'columns' => [
[
'name' => 'country',
'title' => HModule::t('organization', 'Country'),
'options' => [
'class' => 'input-priority'
],
],
[
'name' => 'city',
'title' => HModule::t('organization', 'City'),
'options' => [
'class' => 'input-priority'
],
],
[
'name' => 'street',
'title' => HModule::t('organization', 'Street'),
'options' => [
'class' => 'input-priority'
]
],
[
'name' => 'building',
'title' => HModule::t('organization', 'Building'),
'options' => [
'class' => 'input-priority'
]
],
[
'name' => 'zip_code',
'title' => HModule::t('organization', 'Zip Code'),
'options' => [
'class' => 'input-priority'
]
]
]
]);
?>
...
<?php echo $form->field($license, 'licenseFiles[]')->fileInput(['multiple' => true, 'accept' => 'image/*']) ?>
echo $form->field($modelOrganizationAddress, 'address')->label(HModule::t('organization', 'Address'))->widget(MultipleInput::className(), [
'max' => 4,
'columns' => [
[
'name' => 'country',
'title' => HModule::t('organization', 'Country'),
'options' => [
'class' => 'input-priority'
],
],
[
'name' => 'city',
'title' => HModule::t('organization', 'City'),
'options' => [
'class' => 'input-priority'
],
],
...
[
'name' => 'zip_code',
'title' => HModule::t('organization', 'Zip Code'),
'options' => [
'class' => 'input-priority'
]
]
]
]);
Call to a member function formName() on array
, well, that’s how I get yes, an array of objects Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question