我正在使用CakePHP博客示例:
function add() {
if (!empty($this->data)) {
if ($this->Post->saveAll($this->data)) {
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
}
}}
我希望以添加后将用户重定向到帖子的方式对其进行修改:
但这不起作用:
$this->redirect(array('action' => 'view', $this->Post->id)));
创建后读取模型数据的正确方法是什么?
答案 0 :(得分:1)
正如metrobalderas所说,打破拯救。
if ($this->Post->save($this->data))
{
unset($this->data['Post']; // So that we don't add another
$this->Post->saveAll($this->data);
$this->redirect(array('action' => 'view', $this->Post->id)));
}