Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Redirection loop because of the controller and action values

I'm just starting with Phalcon and decided to slowly port all of my current apps on it. And first problem I've encountered is the redirection to login form. In INVO, the Security.php beforeDispatch() contains call on Dispatcher::forward(), which will display the login form simply anywhere the user actually is. Well, I don't really want this behaviour and want to redirect user to the page with login form instead.

So, I've replaced the Dispatcher::forward() with Response::redirect() but got kicked in the head by infinite loop. The issue is that even after redirection, $dispatcher->getControllerName() still returns the previous controller and thus the ACL rule will fail again and so on.

Can I somehow tell dispatcher "you're done with this controller, forget about it" or am I actually doing it the wrong way? I simply want guest users to be redirected to the login form no matter what address they try to access.

My code is pretty much the same as the INVO, except for the replacement of the Dispatcher::forward() with Response::redirect().

edited Mar '14

controllers/BaseController.php BaseController extends \Phalcon\Mvc\Controller

controllers/LoginController.php LoginController extends \Phalcon\Mvc\Controller

controllers/IndexController.php IndexController extends BaseController

controllers/WhateverController.php WhateverController extends BaseController

class BaseController extends \Phalcon\Mvc\Controller
    public function onConstruct()
        if($allow==false) //your rules when you are sure if $allow is set in session or any other rules

This way you will get what you want :)


Thanks. Will try it this way :)


I found must use send method append redirect like this: