Is it possible to disable an action in pre-dispatch?

1.3k Views Asked by At

In my controller I have a preDispatch method where I check if the user is logged in. If he is not I redirect the user to login form.

Is there any way to disable one of the action's from the preDispatch method? Because I do not need the authorisation for this action.

2

There are 2 best solutions below

1
On BEST ANSWER

In the plugin, you can check if that specific controller and action is being called and allow the request to continue.

Something similar to the following in your plugin will work.

public function preDispatch(Zend_Controller_Request_Abstract $request) {
    // ...

    $controller = $request->getControllerName();
    $action     = $request->getActionName();

    if ($controller == 'login' && $action == 'login') {
        return ; // do not execute any more plugin code
    }

    // deny access and redirect to login form
0
On

I usually use my "Empty" controller/action to do this :

public function preDispatch(Zend_Controller_Request_Abstract $request) {
if (!$logined){
 $request->setControllerName('empty')->setActionName('index');
return;
}
}

It substitute your current action.