1

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

在控制器中

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') ?>
4

0 回答 0