0
votes

In CakePHP, after I have saved a value the database, I'm trying to redirect the page to the index action in the users controller with this code:

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";
                 }
                 }     
            }   
    }

I am getting this error:

        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
There's no need to shout about it. - Wooble
possible duplicate of "Warning: Cannot modify header information - headers already sent by" error (and about a million other questions on SO) - Wooble

2 Answers

0
votes

It looks like you have a space or something before the opening <?php tag in your users_controller.php.

0
votes

You probably already have some output in your users_controller.php on line 1, as the error says. Could be a echo, a newline, something like that.