Yii Framework Forum: Yii Grid, Multiple Management Rows - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Grid, Multiple Management Rows Rate Topic: -----

#1 User is offline   Actimele 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-March 13

Posted 18 March 2013 - 08:59 PM

Hello,
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:

<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>

And save all it like:
 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()... }

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?
0

#2 User is offline   Actimele 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-March 13

Posted 21 March 2013 - 06:57 PM

Why no answers?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users