更新CakePHP中的行

js5cn81o  于 2023-05-29  发布在  PHP
关注(0)|答案(1)|浏览(161)

我有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 ....

kmbjn2e3

kmbjn2e31#

在这里我可以给予你一个例子来编辑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与编辑职位的标题

相关问题