问题描述
我用 predispatch() 方法编写了一个插件来检查每个控制器请求的访问权限.我已将插件制作为:
I wrote a plugin with predispatch() method to check access rights on each controller request . I have made plugin as :
class My_Plugin_Checklogin 扩展 Zend_Controller_Plugin_Abstract {公共函数 preDispatch() {
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
}
}
}
它现在在每个控制器请求之前调用 predispatch().
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.
请帮忙.
推荐答案
对于特定控制器(和/或动作)跳过此插件的最简单方法可能是在插件的 preDispatch 开头添加条件()
方法
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
}
}
这篇关于zend 框架插件——predispatch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!