0
votes

I recently upgraded from CakePHP 1.2 to CakePHP 1.3 and now I have some code that is trapping the user in a redirect loop. This is after the user has successfully logs in and decides to click on a link to manage emails.

I have some code in a controller where the index() method will check if the current user is an admin or not. If the user is not an admin it will do the following:

function index()
{
    if ($this->Session->read('is_admin') < 1) {
        $this->redirect(array('controller' => 'emails', 'action' => 'view', 'id' => $this->Session->read('username')));
    }

    //...more code...
}

This is intended to redirect the user to a view() method and display only their email and not everyone's email. What is happening when I debug this is the redirect keeps ending up in the index() method.

Is there something new in CakePHP that I'm missing? Is it a no-no to use the name "view" as an action in a controller?

* EDIT *

Okay, I was a little premature with this post. The code in the view($username) method is being reached. But the thing is the $username is not defined and I have some client code that is then redirecting back to the index() action if it is not defined.

I did check the original redirect and the $this->Session->read('username') is populated with the username but it is just not being passed in the view()'s $username argument.

Thanks!

1
Does it get to the redirect? or skip over it? Does your application use ACL? Does the user have permission to access the 'view' action? - Moz Morris
Hey Moz, I updated my question with more info. To answer your question it does get to the redirect and my app does use ACL and the user has access to the 'view' action. - programmer
Since I can't answer my own question yet I'll answer it here: It turns out the redirect signature changed from 1.2 to 1.3: book.cakephp.org/view/1561/Migrating-from-CakePHP-1-2-to-1-3 Library Classes > Router // CakePHP 1.2 way $this->redirect(array('controller' => 'emails', 'action' => 'view', 'id' => $this->Session->read('username'))); // CakePHP 1.3 way $this->redirect(array('controller' => 'emails', 'action' => 'view', $this->Session->read('username'))); - programmer

1 Answers

0
votes

It turns out the redirect signature changed from 1.2 to 1.3:

http://book.cakephp.org/view/1561/Migrating-from-CakePHP-1-2-to-1-3 Library Classes > Router

// CakePHP 1.2 way
$this->redirect(array('controller' => 'emails', 'action' => 'view', 'id' => $this->Session->read('username')));

// CakePHP 1.3 way
$this->redirect(array('controller' => 'emails', 'action' => 'view', $this->Session->read('username')));