如何覆盖类 RedirectionStrategy*\vendor\bjyoungblood\bjy-authorize\src\BjyAuthorize\View\RedirectionStrategy.php
以更改$redirectRoute
属性的值?
首先我关注这篇文章:如何使用 BjyAuthorize 重定向到登录页面
谢谢!!
如何覆盖类 RedirectionStrategy*\vendor\bjyoungblood\bjy-authorize\src\BjyAuthorize\View\RedirectionStrategy.php
以更改$redirectRoute
属性的值?
首先我关注这篇文章:如何使用 BjyAuthorize 重定向到登录页面
谢谢!!
我发现: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);
}
}
其作品!
添加 bjyauthorize.global.php
'unauthorized_strategy' => 'BjyAuthorize\View\RedirectionStrategy'
然后在 module.php
use BjyAuthorize\View\RedirectionStrategy;
$strategy = new RedirectionStrategy();
$strategy->setRedirectRoute('zfcuser/login');
$eventManager->attach($strategy);