Yii Framework Forum: Problem With Collecting Tabular Input. - Yii Framework Forum

Jump to content

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

Problem With Collecting Tabular Input. Rate Topic: -----

#1 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 08-May 12

Posted 16 February 2013 - 10:18 AM

I want to know why $item->attributes = $_POST['Member'][$i]; won't work.Any body please help me.

In my controller.
        $items = $this->getItemsToUpdate($id);
        if (isset($_POST['Member'])) {
            foreach ($items as $i => $item) {
                if (isset($_POST['Member'][$i]))  {
                        $item->attributes = $_POST['Member'][$i];// This won't work,product_print won't update when saved.
                        $item->product_print=$_POST['Member'][$i]['product_print'];// This will work,product_print will be     update when saved
                        $item->save();
                  }
            }
        }
        $this->render('view', array(
            'model' => $this->loadModel($id),
            'items' => $items,
        ));
    }

    public function getItemsToUpdate($id) {
        $items = Member::model()->findAll('groupid=' . $id);
        return $items;
    }


In my view.
<?php foreach($items as $i=>$item): ?>
<?php echo CHtml::activeTextField($item,"[$i]product_print"); ?>
<?php endforeach; ?>

0

#2 User is offline   Keith 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 835
  • Joined: 04-March 10
  • Location:UK

Posted 16 February 2013 - 10:39 AM

You need to make sure that product_print has a validation rule in the current scenario. If any value is acceptable, you can use the 'safe' rule.

array('product_print', 'safe'),

0

#3 User is offline   nakarin 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 08-May 12

Posted 16 February 2013 - 10:55 AM

View PostKeith, on 16 February 2013 - 10:39 AM, said:

You need to make sure that product_print has a validation rule in the current scenario. If any value is acceptable, you can use the 'safe' rule.

array('product_print', 'safe'),



Thank you very much Keith,It 's working now. :rolleyes:
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