Answer the question
In order to leave comments, you need to log in
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.
The shape is like the picture. What should be done to make model->save work for all rows???
I think so :
$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);
Answer the question
In order to leave comments, you need to log in
Dear Bahodir Ismatov , You would start by reading the yii2 documentation and simple forms, and only then would you take on complex forms.
Use $_POST
using 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 questionAsk a Question
731 491 924 answers to any question