Yii网格,多个管理行

Yii网格,多个管理行,yii,rows,Yii,Rows,我有一个关于网格中管理行的问题。例如,我们有食物/成本表,如: Fruit | cost ------------ Apple | 10$ Bannan| 5$ 我们可以创建如下形式: <form> <input type='text' name='Fruits[0][fruit] value='Apple' /> <input type='text' name='Fruits[0][cost] value='10$' /> <br> <

我有一个关于网格中管理行的问题。例如,我们有食物/成本表,如:

Fruit | cost
------------
Apple | 10$
Bannan| 5$
我们可以创建如下形式:

<form>
<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$' />
</form>
好的,我们可以同时更新两行。。。但如果我想添加新的?上面所有的好方法都很好,但是如果我删除一行呢?在我的基地,我将有2行,但我只需要1

我有两种看法: 1.每次更新时,在POST计数时从数据库中删除所有水果!=数据库计数 2.我们可以加载数据库行,写循环,检查每一行。。。但是它太难了,太多的代码


如何管理新行和已删除行?

使用Yii数据处理程序打印结果,如“CGridView”:

 if ($is_new)
    if(isset($_POST['Fruits'])) {
      foreach ($_POST['Fruits'] as $fruit) {
        $model = new Fruit();
        $model->attributes = $fruit;
        $model->save();
      }
    }
} else { //here code for update, $model->load()... }