0
votes

In CakePHP 2x I want to display some text when some condition is met and forward to another page when another condition is met, something like the code below. But this second part is not working.I know redirect only works from controller. Is there any way to do this in view?

if ($enable==2){ 
    echo $introduction; 
    } 
elseif ($enable==1){ 
    **$this->redirect(array('controller'=>'pages' , 'action' => 'home'));**
     }

Thanks in advance.

2
Why can't you do the redirect in the controller, that would be easier?toby1kenobi

2 Answers

0
votes

Try use js helper as shown bellow:

$this->Js->domReady('window.location.href="/your/URL/Here";');
0
votes

It looks like your logic is correct, but your redirect() url is not.

Your Controller (not your View) should have this as the redirect:

$this->redirect(array('controller'=>'pages', 'action'=>'display', 'home'));

The PagesController works a little differently than your other controllers. By default, it uses the 'display' action to render pages. You then pass the page name after that.

Here's some more info on the PagesController: http://book.cakephp.org/2.0/en/controllers/pages-controller.html

Hope that helps.