1

データベースに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 に答える