问题描述
我正在创建已配置的维护页面。
我创建了一个事件订阅者:
public function onKernelRequest(RequestEvent $event)
{
$maintenance = $this->container->hasParameter('maintenance') ? $this->container->getParameter('maintenance') : false;
$underMaintenanceUntil = $this->container->hasParameter('underMaintenanceUntil') ? $this->container->getParameter('underMaintenanceUntil') : false;
if (!$event->isMasterRequest()){
return;
}
$debug = in_array($this->container->get('kernel')->getEnvironment(),['test','dev']);
$uri = $event->getRequest()->getRequestUri();
if ($uri == '/login' || $uri == '/logout') {
return;
}
if ($maintenance && !$debug && !$this->container->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
$engine = $this->container->get('twig');
$content = $engine->render('pages/maintenance.html.twig',array('underMaintenanceUntil' => $underMaintenanceUntil));
$event->setResponse(new Response($content,503));
$event->stopPropagation();
}
}
分析器栏不起作用。我得到
加载Web调试工具栏时发生错误。
在日志中:
[应用] 10月5日08:24:41 |信息|请求匹配的路线“ _wdt”。 method =“ GET” request_uri =“ https:// localhost:8001 / _wdt / 914ef7” route =“ _ wdt” route_parameters = {“ _ controller”:“ web_profiler.controller.profiler :: toolbarAction”,“ _ route”:“ _ wdt”,“令牌”:“ 914ef7”} [应用程序] 10月5日08:24:41 | CRITICA |请求未捕获的PHP异常 Symfony \ Component \ Security \ Core \ Exception \ AuthenticationCredentialsNotFoundException: “令牌存储区不包含身份验证令牌。一种可能 原因可能是没有为此URL配置防火墙。” /home/marcin/projects/indali/vendor/symfony/security-core/Authorization/AuthorizationChecker.php 第52行
即使我输入/login
页面,我也会遇到相同的错误。 if ($uri == '/login' || $uri == '/logout') {return;}
是否应该阻止不执行其他代码(如果它是登录uri)?
此$this->container->get('security.authorization_checker')->isGranted('ROLE_ADMIN')
产生了我的错误,因为在开发防火墙中没有身份验证令牌。我可以检查令牌是否存在,但是我的代码为什么不起作用?。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)