B
B
Bahodir Ismatov2018-08-17 14:22:09
Yii
Bahodir Ismatov, 2018-08-17 14:22:09

How to create a Controller for multiple insert data?

Hello! Please help me implement this.
Is it possible to make a model as an array? Because I have 6 days in the form.
5b76af4dabc55392597013.png
The shape is like the picture. What should be done to make model->save work for all rows???
I think so :

spoiler
$model = new Schedule();
        $count=0;
        if (isset($_POST['Group_id']) && $_POST['Group_id']!=null)
        $model->Group_id = $_POST['Group_id'];
        for ($i=1; $i<=6; $i++){
            $model->Day_id = $i;
            for ($j=1; $j<=4; $j++){
                if (isset($_POST[$i.'_subject_'.$j]) && $_POST[$i.'_subject_'.$j]!=null) {
                   $model->pair = $_POST[$i.'_pair_'.$j];
                   $model->Subject_id = $_POST[$i.'_subject_'.$j];
                   $model->type = $_POST[$i.'_type_'.$j];
                   $model->Teacher_id = $_POST[$i.'_teacher_'.$j];
                   $model->isEven = $_POST[$i.'_even_'.$j];
              
                    $model->save();
                    $count++;
                }
            }
        }
            print_r($model);


Please help, I have been unable to do this for 5 days!
Thanks in advance, looking forward to your reply!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-08-17
@Baxa94

Dear Bahodir Ismatov , You would start by reading the yii2 documentation and simple forms, and only then would you take on complex forms.
Use $_POSTusing framework - mauvais ton!!!
And the rest, too, bullshit on a moonlit night.
Read the articles and documentation on the links that I gave you earlier.
And I repeat once again, you need the so-called "Table entry"!!!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question