zf2 - 如何覆盖BjyAuthorize \ View \ RedirectionStrategy

时间:2013-08-22 10:41:07

标签: zend-framework2 bjyauthorize

如何更改*\vendor\bjyoungblood\bjy-authorize\src\BjyAuthorize\View\RedirectionStrategy.php中的类RedirectionStrategy以更改$redirectRoute属性的值?

http://pastebin.com/pPKsZcC5

首先,我关注此帖:How to redirect to the login page with BjyAuthorize

谢谢!

2 个答案:

答案 0 :(得分:3)

我找到了:https://github.com/bjyoungblood/BjyAuthorize/blob/master/docs/unauthorized-strategies.md

    namespace MyApp;

use BjyAuthorize\View\RedirectionStrategy;

class Module
{
    public function onBootstrap(EventInterface $e) {
        $application  = $e->getTarget();
        $eventManager = $application->getEventManager();

        $strategy = new RedirectionStrategy();

        // eventually set the route name (default is ZfcUser's login route)
        $strategy->setRedirectRoute('my/route/name');

        // eventually set the URI to be used for redirects
        $strategy->setRedirectUri('http://example.org/login');

        $eventManager->attach($strategy);
    }
}

这是有效的!

答案 1 :(得分:0)

添加bjyauthorize.global.php

'unauthorized_strategy' => 'BjyAuthorize\View\RedirectionStrategy'

然后在module.php中

        use BjyAuthorize\View\RedirectionStrategy;
        $strategy = new RedirectionStrategy(); 
        $strategy->setRedirectRoute('zfcuser/login'); 
        $eventManager->attach($strategy);