good_evening
good_evening

Reputation: 21739

Redirecting fails in CakePHP

public function index()
{
    $this->redirect('/');
}   

I will just go insane soon... How can it not work? Please help.

EDIT: by won't work I mean it gives just blank page.

EDIT2: Redirect doesn't work in all controllers!

Upvotes: 0

Views: 1092

Answers (4)

Piotr Chabros
Piotr Chabros

Reputation: 475

$this->redirect(array('url' => '/'));

OR

$this->redirect(array('controller' => 'examples', 'action' => 'add'));

Upvotes: 0

good_evening
good_evening

Reputation: 21739

I had controller's class like this:

<?
class PageController extends AppController
{

I had a new line before <?, that's why it didn't work. :)

Upvotes: 1

Andreas Wong
Andreas Wong

Reputation: 60516

If your index() is actually a controller action referring to '/' then you'll have an infinite redirect loop and that could be the cause of your problem.

Please add more context to your question to have a better chance in getting a correct answer.

If you are getting blank pages, could very well be your configuration, try enabling debug by editing the line

Configure::write('debug', 0) to Configure::write('debug', 2) in your core.php and see what's wrong

Upvotes: 0

user1289347
user1289347

Reputation: 2407

Try setting it absolutely

$this->redirect('http://www.example.com');

Upvotes: 0

Related Questions