Answer the question
In order to leave comments, you need to log in
Why is the model not loading after submitting data?
The site has a form in which there are several different models.
The form:
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'pagetitle')->textInput(['maxlength' => true]) ?>
<?= $form->field($collections, 'id')->dropDownList(\backend\models\Collections::find()
->select(['name'])
->indexBy('id')
->column(), ['prompt'=>'Выберите коллекцию'])
->label('Коллекция')
->error(['text' => 'Это поле обязательное']) ?>
<?= $form->field($image, 'images[]')->fileInput(['multiple' => true, 'accept' => 'image/*']) ?>
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>
$collections->load(Yii::$app->request->post('Collections'));
var_dump(Yii::$app->request->post('Collections'));
/*
../ProductsController.php:89:
array (size=1)
'id' => string '2' (length=1)
*/
var_dump($collections->id);
/*
../ProductsController.php:91:null
*/
public function rules()
{
return [
[['id'], 'required'],
[['id'], 'integer'],
[['name'], 'string', 'max' => 75],
];
}
if($model->load(Yii:$app->request->post()) && $model->save())
{
// Если убрать save(), и вызвать $model->pagetitle то null
return $this->redirect(['view', 'id' => $model->id]);
}
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