我设置了一个编辑页面来编辑博客文章。这是控制器动作...
public function edit($id = null) {
$post = $this->Post->findById($id);
if(!$post) {
throw new NotFoundException('Post not found');
}
if($this->request->is('post')) {
$this->Post->id = $id;
if($this->Post->save($this->request->data)) {
$this->Session->setFlash('Post updated!');
$this->redirect('/');
} else {
$this->Session->setFlash('Unable to update post!');
}
}
if (!$this->request->data) {
$this->request->data = $post;
}
$this->set('tags', $this->Post->Tag->find('list'));
$this->set('pageTitle', 'Edit blog post');
}
和编辑页面视图...
<h1>Edit blog post</h1>
<?php echo $this->Form->create('Post'); ?>
<?php echo $this->Form->input('Post.title'); ?>
<?php echo $this->Form->input('Post.body'); ?>
<?php echo $this->Form->input('Tag.Tag', array('type' => 'text', 'label' => 'Tags (seperated by space)', 'value' => $tags)); ?>
<?php echo $this->Form->input('Post.slug'); ?>
<?php echo $this->Form->end('Save Changes'); ?>
出于某种原因,当我进行更改并单击“保存更改”时,页面会刷新,尽管更改会在刷新后反映在表单中,但我必须再次单击“保存更改”才能将它们保存到数据库中蛋糕将我重定向到/
。
可能是什么原因造成的?