zend-frameworkzend-controller

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


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.


Solution

  • 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