我正在学习 Cakephp 框架。我在尝试更新数据库记录时遇到问题。
这是编辑帖子的控制器代码....
$this->loadModel('Post');
if($this->request->is('put')):
$this->Post->id = $this->params['id'];
if($this->Post->save($this->request->data)):
$this->Session->setFlash(__('Page has been edited'));
$this->redirect('/User/index');
endif;
else:
$this->set('postinfo', $this->Post->findById($this->params['id']));
endif;
}
这是 view/edit.ctp 文件
echo $this->Form->update('Post', array(
'method' => 'put'
));
echo $this->Form->input('title',array('type' => 'text','value'=>$postinfo['Post']['title']));
echo $this->Form->input('body', array('type' => 'textarea','value' => $postinfo['Post']['body']));
echo $this->Form->submit('Submit', array('class'=>'btn btn-primary'));
echo $this->Form->end();
但是这段代码并没有更新数据库中的记录……我尝试了 book.cakephp.org 教程和其他与 cakephp 相关的教程。我希望能得到你们的帮助:)