zend 框架插件 - predispatch()

发布于 2024-09-17 01:30:14 字数 629 浏览 1 评论 0原文

我用 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() 。

但也不允许我登录。由于预调度方法,总是让我处于登录页面。我必须如何设置预调度方法。

请帮忙。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2024-09-24 01:30:17

对于特定控制器(和/或操作)跳过此插件的最简单方法可能是在插件的 preDispatch() 方法的开头添加条件

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
    }
}

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文