2

我有这个问题。在我的 ZF2 应用程序中,我使用 byjauthorize 和 zfcuser 管理登录系统,并且我有两种不同的基本布局。一个专用于登录页面,一个专用于用户登录时的应用程序。这是 module.config.php 中 Application 模块中的代码:

'template_map' => array(
            'layout/login_layout'     => __DIR__ . '/../view/layout/login_layout.phtml',
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',

现在总是在 Module.php 中的应用程序模块,我设置了这个代码:

public function onBootstrap(MvcEvent $e)
    {
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);

        $application = $e->getTarget();

        // Change default layout if user is logged
        $sm = $application->getServiceManager();
        $auth = $sm->get('zfcuser_auth_service');

        if ($auth->hasIdentity()) {

            $eventManager->attach("dispatch", function($e) {
                $controller = $e->getTarget();

                $s_matchedRoute = $e->getParam('route-match')->getMatchedRouteName();

                    if ($s_matchedRoute === 'zfcuser/login') {

                        $controller->layout('layout/login_layout');

                    } else {

                        $controller->layout('layout/layout');
                    }
                });

                /*
                 * Check Admin ACL with BjyAuthorize:
                 * use RedirectionStrategy (that redirects to ZfcUser's login route by default)
                 */
                $strategy = new RedirectionStrategy();
                $strategy->setRedirectRoute('application/error');
                $e->getTarget()->getEventManager()->attach($strategy);

        } else {

            $eventManager->attach("dispatch", function($e) {
                $controller = $e->getTarget();
                $controller->layout('layout/login_layout');
            });

            $strategy = new RedirectionStrategy();
            $strategy->setRedirectRoute('zfcuser/login');
            $e->getTarget()->getEventManager()->attach($strategy);
        }

        /**
         * Format style login page
         */
        $this->layoutFormLogin($eventManager);

        // Setting function to handler error
        set_error_handler(array('Application\Module','handlePhpErrors'));
    }

但是当 $auth->hasIdentity 为 false 时,RedirectionStrategy 不会重定向 zfcuser/login 中的路由。哪里错了?ps 我的 application.config.php 是这样的:

     // 3rd part modules
    'DoctrineModule',
    'DoctrineORMModule',
    'ZendDeveloperTools',
    'ZfcBase',
    'ZfcUser',
    'ZfcUserDoctrineORM',
    'BjyAuthorize',
    'DOMPDFModule',
    'WebinoImageThumb',

    //My Module
    'Application',
4

0 回答 0