Yii Grid, Multiple Management Rows


i have a questions about managament rows in grid. For example we have food/cost table like:

Fruit | cost

Apple | 10$

Bannan| 5$

We can create form like:


<input type='text' name='Fruits[0][fruit] value='Apple' /> <input type='text' name='Fruits[0][cost]  value='10$' /> <br>

<input type='text' name='Fruits[1][fruit] value='Bannan' /> <input type='text' name='Fruits[1][cost]  value='5$' />


And save all it like:

 if ($is_new)

    if(isset($_POST['Fruits'])) {

      foreach ($_POST['Fruits'] as $fruit) {

        $model = new Fruit();

        $model->attributes = $fruit;




} else { //here code for update, $model->load()... }

All fine, we can update both rows… But that if i want add new? All fine method above make all good, but what if i delete 1 row? In my base i will have 2 rows, but i need only 1.

Here 2 ways i see: 1. Delete all fruits from databse on every update when POST count != databse count 2. We can load database rows, write loop, check every row… but its so hard, so many code…

How you manage new and deleted rows?

Why no answers?