CakePHP:从Ipr_forms表中获取IprForm ID并更新表的行

时间:2013-07-30 06:39:23

标签: cakephp cakephp-2.0

我在我的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,$id变量保持job_id ....

1 个答案:

答案 0 :(得分: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 link