1

我的 Db 中有Ipr_forms表我想更新该行但下面的代码给了我job_id该表。这不是我的要求.....我希望表 id 更新现有表

我的控制器代码

          $id =$this->request->data['IprForm']['id'];                                                                           
          $ipr_forms['job_id'] =  $this->request->data['IprForm']['job_id'];
          $ipr_forms['IprForm'] =  $this->request->data['IprForm'];           
          $this->IprForm->id = $id;
        //debug($id); 
          $ipr_forms_save = $this->IprForm->save($ipr_forms);

如果我调试 id ,$id变量保存 job_id ....

4

1 回答 1

1

在这里我可以给你一个例子来编辑 cakephp 中具有多个字段的任何记录

看看功能,你可能有个好主意

public function edit($id = null) {
    if (!$id) {
        throw new NotFoundException(__('Invalid post'));
    }

    $post = $this->Post->findById($id);
    if (!$post) {
        throw new NotFoundException(__('Invalid post'));
    }

    if ($this->request->is('post') || $this->request->is('put')) {
        $this->Post->id = $id;
        if ($this->Post->save($this->request->data)) {
            $this->Session->setFlash(__('Your post has been updated.'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('Unable to update your post.'));
        }
    }

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

或者您也可以参考带有编辑帖子标题的详细cakephp.org 链接

于 2013-07-30T09:20:32.183 回答