从表中获取ID并更新CakePHP中的行
我的数据库中有从表中获取ID并更新CakePHP中的行,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我的数据库中有Ipr_表单表我想更新该行,但以下代码为我提供了该表的job_id。这不是我的要求…..我希望表id更新现有表 我的控制器代码 $id =$this->request->data['IprForm']['id']; $ipr_forms['job_id'] = $this->
Ipr_表单
表我想更新该行,但以下代码为我提供了该表的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
变量hold the job_id…这里我可以给你一个例子,用多个字段编辑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编辑任何带有多个字段的记录 只要看看函数,你可能会有一个好主意
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;
}
}
或者你也可以参考编辑文章标题的细节