Answer the question
In order to leave comments, you need to log in
(Yii2) How to save multiple rows to the database at once?
Did something similar to this
. All users are displayed from the database. Click to edit the fields.
I assign names to inputs which should be Users[name] depending on the field type.
But there is no way to save everything if several fields are edited
Answer the question
In order to leave comments, you need to log in
Well, you cycle through the array and break it into queries.
Why shove everything in 1 request? Yes, and you can do only one insert, update will not work.
Made it like this
I wrap it in input and add the post id to the field type.
Then I sort in the controller
foreach($_POST['Users'] as $key=>$value){
list($id, $name) = explode("_", $key);
$user = Users::findOne($id);
$user->$name = $value;
$user->save();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question