YII2 update multiple lines at the same time

I have listed multiple rows of data from a database in a GridView. Now I need to update certain fields (all the same types, i.e. having the same names but different values) in the GridView and update the values ​​in the database. A cell in matter is returned like this:

return Html::input('text', '['.$data->country_id.']country_polity', $data->country_polity, ['class' => 'form-control']);

      

So, in general, I want to be able to display country policies in the GridView and provide the user with the ability to update those values ​​in the GridView.

I have looked at various tutorials (example below) and all tutorials are about inserting data into a database, not updating. However, I have not been able to get started implementing these tutorials to get through with my goal.

http://www.yiiframework.com/wiki/666/handling-tabular-data-loading-and-validation-in-yii-2/

loadMultiple()

returns nothing to me, possibly due to inaccurate ways of defining the countries whose values ​​need to be changed.

So how should I proceed? foreach

each item $_POST

and store them separately for the corresponding DB row?

+3


source to share


1 answer


I think you can do this in your controller. First you can get models from $ _POST using

$post = Yii::$app->request->post();
$yourModels = $post['yourModelName'];

      



then just

foreach ($yourModels as $model) {
            model->save(false);
}

      

+5


source







All Articles