Revision #7 has been created by Said Bakr on Jan 20, 2016, 9:53:15 PM with the memo:
Add prebuilt solution to option 1.
« previous (#6)
Changes
Title
unchanged
Handling tabular data loading and validation in Yii 2
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
yii, yii2, tabular, data, multiple, record, submission, validation, save
Content
changed
[...]
If you are coming over from Yii 1 - the concepts of tabular data handling remain the same as mentioned in the [Yii 1.x guide - collecting tabular input section](http://www.yiiframework.com/doc/guide/1.1/en/form.table "").
The only differences in Yii 2 is that its much simpler due to available functions in the Model class for loading and validating models.
### OPTION 1: USING A PREBUILT SOLUTION
You can use a prebuilt solution to render and manage tabular data. You can use the [TabularForm widget](http://demos.krajee.com/builder-details/tabular-form "") or [yii2-dynamicform](https://github.com/wbraganca/yii2-dynamicform).
### OPTION 2: DOING IT YOURSELF
You can use the same concepts as mentioned in the guide link mentioned before - here are the changes you need to do for Yii 2:
To work with tabular input, we first need to create or populate an array of model instances, depending on whether we are inserting or updating the data. We then retrieve the user input data from the `$_POST` variable and assign it to each model. A slight difference from single model input is that we retrieve the input data using $_POST['ModelClass'][$i] instead of $_POST['ModelClass'].[...]