zend framework plug-in - predispatch()

你。 提交于 2019-12-25 04:57:46

问题


I wrote a plugin with predispatch() method to check access rights on each controller request . I have made plugin as :

class My_Plugin_Checklogin extends Zend_Controller_Plugin_Abstract { public function preDispatch() {

    if (isset($_SESSION['Zend_Auth_Static'])) {
        //no login
        $request = $this->getRequest();
        //the request
        $request->setModuleName('default');
        $request->setControllerName('index');
        $request->setActionName('index');
        //send to default/login/index
    }
}

}

It's calling predispatch() before each controller request now.

But also not allowing me to log in. always keeping me on login page due to predispatch method. How I have to set predispatch method.

Please help.


回答1:


Probably the easiest way to skip this plugin for a particular controller (and/or action) is to add a conditional at the beginning of the plugin's preDispatch() method

public function preDispatch(Zend_Controller_Request_Abstract $request)
{
    if ($request->getModuleName() == 'default' 
     && $request->getControllerName() == 'login'
     && $request->getActionName() == 'index') {
        return ;
    }

    if (isset($_SESSION['Zend_Auth_Static'])) {
       // your code goes here
    }
}


来源:https://stackoverflow.com/questions/3627156/zend-framework-plug-in-predispatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!