Saving and Updating model using dropdownlist of multiple items


Please I need to be able to save multiple items items to a model using a dropdown list. I have searched all around the web and could not find a solution. Basically my problem is this: I have offices and need to assign users to selected offices. I should be able to select multiple users from a drop down list and add them to the database as well as edit the added users.

How do I achieve this in yii2?

Sample code:

<select multiple="multiple">

<option value =‘1’>Daniel Bahm</option>

<option value =‘2’>Susan Hardy</option>

<option value =‘3’>Gabriel Dan</option>


I need sample controller code explaining how to save multiple items from a drop down list to the database, as well as update the list of saved items. By default yii2 can easily handle saving and updating single items from a dropdown list but I am yet to find an example on the net where multiple items were saved from a dropdown and updated.

Any sample code will be appreciated

Sorry, I have no example code ready because I did nothing like that in Yii2 until now…

But what you are looking for is called "Batch Input" or "Tabular Input".

I found for example this:

Its not very much info - but I hope you understand the idea / principle behind it. :)