使用mysql在cakephp中进行多次编辑

时间:2013-07-09 06:50:32

标签: cakephp

我正在尝试在单个表中进行多次更新 下面我描述控制器,视图编码

在控制器中

public function multiEdit($oid,$cid){
  $this->set('oid',$oid);
  $this->set('cid',$cid);


  $this->set('oid',$oid);
  $this->set('cid',$cid);

  $item = $this->Item->find('all',array('conditions' => array('Item.order_id' => $oid,'Item.visible'=>true)));

    if($this->request->is('post') || $this->request->is('put')){

        if($this->Item->saveAll($this->data)){

            $this->Session->setFlash('Item Information has been updated',true);
            $this->redirect(array('action' =>'index',$oid,$cid));
        }else{
            $this->Session->setFlash('Unable to update Item information',true);
        }
    }

    if(!$this->request->data){
        $this->request->data = $item;
    }

}

在视图中

<?php echo $this->Form->create('Item');?>
<?php foreach ($this->data as $i => $item): ?> 
<?php

echo $this->Form->hidden("Item.$i.id", array('value' => $item['Item']['id']));
echo $this->Form->input("Item.$i.name", array('value' => $item['Item']['name']));
echo $this->Form->hidden("Item.$i.code", array('value' => $item['Item']['code']));
echo $this->Form->hidden("Item.$i.qnty", array('value' => $item['Item']['qnty']));
echo $this->Form->hidden("Item.$i.price", array('value' => $item['Item']['price']));
echo $this->Form->input("Item.$i.sent", array('value' => $item['Item']['sent']));
echo $this->Form->hidden("Item.$i.ac_sent", array('value' => $item['Item']['ac_sent']));
echo $this->Form->hidden("Item.$i.visible", array('value' => $item['Item']['visible']));?

<?php  endforeach; echo $this->Form->end('Save Item') ?>

0 个答案:

没有答案