Cakephp:在add函数中访问数据

时间:2010-12-24 20:25:13

标签: cakephp

我正在使用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)));    

创建后读取模型数据的正确方法是什么?

1 个答案:

答案 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)));
}