如何更新多个模型

时间:2014-05-11 22:21:40

标签: php cakephp

尝试编辑多个模型

控制器

public function admin_edit($id = null) {
    $this->set('title_for_layout', __('Edit Ticket'));

    if (!$id && empty($this->request->data)) {
        $this->Session->setFlash(__('Invalid Ticket'), 'default', array('class' => 'error'));
        $this->redirect(array('action' => 'index'));
    }
    $post = $this->Ticket->findById($id);
    if (!empty($this->request->data)) {
        $this->Ticket->id = $id;
        //$this->Model1->saveAssociated($this->request->data);
    if ($this->Ticket->saveAll($this->request->data)) {
        $this->request->data['Detail']['ticket_id']=$this->Ticket->id;
        $this->Detail->save($this->request->data);
        $this->Session->setFlash(__('Your post has been updated.'));
        return $this->redirect(array('action' => 'index'));
    }
    $this->Session->setFlash(__('Unable to update your post.'));
}

       if (!$this->request->data) {
             $this->request->data = $post;
                }
   //$this->set('count',$count);

    }

视图

    <?php echo $this->Form->create('Ticket');?>

                 <?php echo $this->Form->input("Ticke.0.nom_model",array('label' => 'nom model' ));
                echo $this->Form->checkbox("Detail.0.bold", array('value' => 1));
                echo $this->Form->checkbox("Detail.0.italic", array('value' => 1));
                echo $this->Form->input("Detail.0.taille");
                echo $this->Form->input("Detail.0.police");
                echo $this->Form->hidden("Detail.0.nom",array('value' => 'msg3'));
                echo $this->Form->hidden("Detail.0.ticket_id",array('value' => $count));
                echo $this->Form->input("Detail.0.text");
                echo $this->Form->checkbox("Ticket.0.is_active", array('value' => 1));
                echo $this->Form->end(__('Save'));

它不能正常工作!!我正在尝试编辑和更新相关模型,故障单和详细信息中的信息。信息显示在视图中。但是当我提交表格时。

票证信息正在保存,没有任何问题。但是步骤信息没有更新

模型是相关的。详情属于门票,门票有很多详细信息

0 个答案:

没有答案