A
A
Alexander Surkov2020-09-13 11:02:49
Yii
Alexander Surkov, 2020-09-13 11:02:49

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]);
    }


This is what the view looks like:
<?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();
?>


As you can see, almost copy-paste. However, the "SkillsChecked::loadMultiple" method does not return any values ​​at all. I must have done something wrong somewhere, right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-09-13
@looserrick

Good afternoon.
Replace

SkillsChecked::loadMultiple($sk_ch, Yii::$app->request->post(), '')

on the
Model::loadMultiple($sk_ch, Yii::$app->request->post())

And yet, you don't have any $settings)))
Replace
SkillsChecked::validateMultiple($settings))
with
Model::validateMultiple($sk_ch))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question