You are outputting text to the screen before you do the redirect, so it won't
work. Rather than doing (and I am guessing what you are doing here) this:
echo "Congratulations, your new account has been successfully created";
$this->redirect...etc
...place the text into the session flash:
$this->Session->setFlash('Congratulations, your new account has been
successfully created');
...and then echo it out in the view you are sending them to:
echo $this->Session->flash();
Jeremy Burns
Class Outfit
[email protected]
http://www.classoutfit.com
On 6 Oct 2010, at 22:17, a17s wrote:
> Hello, got a problem with using cakephp redirect. Get an error saying
> header already been set. Please how can I redirect to another action
> after processing a post. My error keeps pointing to the cake/
> basic.php, and the controller/controller.php
>
> See error and code below:
>
> Error
> ====
> Congratulations, your new account has been successfully created
>
> Warning (2): Cannot modify header information - headers already sent
> by (output started at /home/asco3112/public_html/projects/library/cake/
> basics.php:655) [CORE/cake/libs/controller/controller.php, line 746]
> Code | Context
>
> $status = "Location: http://a17s.com/projects/library/users"
>
> header - [internal], line ??
> Controller::header() - CORE/cake/libs/controller/controller.php, line
> 746
> Controller::redirect() - CORE/cake/libs/controller/controller.php,
> line 725
> UsersController::register() - APP/controllers/users_controller.php,
> line 97
> Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
> Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
> [main] - APP/webroot/index.php, line 83
>
> Code
> ====
> function register(){
> if(!empty($this->data)){
> $this->User->create($this->data);
> if($this->User->save($this->data)){
> $this->Session->setFlash(__('Congratulations,
> your new account has
> been successfully created'));
> unset($this->data);
> $this->redirect(array('controller'=>'users',
> 'action'=>'index'));
> }
> else{
> //unable to save data
> $this->Session->setFlash(__('Unable to register
> user, please try
> again'));
>
> }
> }
> }
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en