cakephp中的重定向问题

时间:2011-08-11 12:58:55

标签: cakephp

在CakePHP中,在我保存数据库的值之后,我正在尝试使用以下代码将页面重定向到用户控制器中的索引操作:

function add(){
         if (!empty($this->data)) {  
             if ($this->User->save($this->data['User'])) {      

                // $this->User->Post->date=$this->data['Post']['date1'];
                // $this->data['Post']->;
            //  echo $this->User->Post->user_id;
                $this->User->Post->set($this->data['Post']);
                $this->User->Post->set('user_id' ,$this->User->getInsertID());
                 if ($this->User->Post->save()) {   
                        // $this->Session->setFlash('Your post has been saved.'); 
                         $this->redirect(array('action'=>'index')); 
                         echo "test";
                 }
                 }     
            }   
    }

我收到此错误:

        Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\students\app\controllers\users_controller.php:1) [CORE\cake\libs\controller\controller.php, line 742]

2 个答案:

答案 0 :(得分:0)

您的<?php中的users_controller.php标记开头看起来有空格或其他内容。

答案 1 :(得分:0)

您可能已经在第1行的users_controller.php中输出了一些内容,正如错误所示。可以是echo,换行符,类似的东西。

相关问题