Answer the question
In order to leave comments, you need to log in
Why doesn't loadMultiple work for the model?
I'm new to Yii2 (in PHP, in general, too), trying to copy- paste from here to change the fixed set of records.
There is a skills_checked table (there is only one 'value' field that needs to be changed), for which I generated a model using Gii. Then I did the following action in the controller:
public function actionUpdate($id)
{
$sk_ch = SkillsChecked::find()->indexBy('id')->where(['students_id' => $id]);
if (SkillsChecked::loadMultiple($sk_ch, Yii::$app->request->post(), '') && SkillsChecked::validateMultiple($settings)) {
foreach ($sk_ch as $sk) {
$sk->save(false);
}
return $this->redirect('index');
}
$dataProvider = new ActiveDataProvider([
'query' => $sk_ch,
]);
return $this->render('update', ['models' => $dataProvider, 'id' => $id]);
}
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\bootstrap\Button; ?>
<?php $form = ActiveForm::begin([
'id' => 'update',
'options' => ['class' => 'form-horizontal'],
]); ?>
<?php
foreach ($models->getModels() as $index=>$model) {
echo $form->field($model, "[$index]value")->label($model->skills_id);
} ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end();
?>
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Replace
SkillsChecked::loadMultiple($sk_ch, Yii::$app->request->post(), '')
Model::loadMultiple($sk_ch, Yii::$app->request->post())
SkillsChecked::validateMultiple($settings))
Model::validateMultiple($sk_ch))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question