Php Symfony3 security.exception\u listener.class不工作

Php Symfony3 security.exception\u listener.class不工作,php,symfony,Php,Symfony,我正试图在Symfony security中操作登录目标路径,因为我的应用程序会进行一些AJAX调用。我照做了,但什么也没发生(所以我假设安全性.exception\u listener.class没有正确地“钩住”)。当我在Google上搜索时,我在github上发现了2015年的版本,该版本声称提供的文档中的解决方案在Symfony>=3中无效 现在我只是想知道-有人知道链接的文档是否真的过时了(这似乎是我的问题),以及如何在Symfony 3中完成同样的事情吗?Symfony 2.7的文档

我正试图在Symfony security中操作登录目标路径,因为我的应用程序会进行一些AJAX调用。我照做了,但什么也没发生(所以我假设
安全性.exception\u listener.class
没有正确地“钩住”)。当我在Google上搜索时,我在github上发现了2015年的版本,该版本声称提供的文档中的解决方案在Symfony>=3中无效


现在我只是想知道-有人知道链接的文档是否真的过时了(这似乎是我的问题),以及如何在Symfony 3中完成同样的事情吗?

Symfony 2.7的文档已更新为使用编译器过程:

我想这一变化很快就会进入文档的更高版本

//src/AppBundle/Security/Firewall/ExceptionListener.php
命名空间AppBundle\Security\Firewall;
使用Symfony\Component\HttpFoundation\Request;
使用Symfony\Component\Security\Http\Firewall\ExceptionListener作为BaseExceptionListener;
类ExceptionListener扩展了BaseExceptionListener
{
受保护的函数setTargetPath(请求$Request)
{
//不保存XHR请求的目标路径
//你可以在这里添加任何你想要的逻辑
//请注意,非GET请求已被忽略
如果($request->isXmlHttpRequest()){
返回;
}
父::setTargetPath($request);
}
}
//src/AppBundle/DependencyInjection/Compiler/ExceptionListenerPass.php
命名空间AppBundle\DependencyInjection\Compiler;
使用Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
使用Symfony\Component\DependencyInjection\ContainerBuilder;
使用AppBundle\Security\Firewall\ExceptionListener;
类ExceptionListenerPass实现CompilerPass接口
{
公共函数进程(ContainerBuilder$container)
{
//使用防火墙的名称作为后缀,例如“安全区域”
$definition=$container->getDefinition('security.exception\u listener.securited\u area');
$definition->setClass(异常Listener::class);
}
}
//src/AppBundle/AppBundle.php
名称空间AppBundle;
使用AppBundle\DependencyInjection\Compiler\ExceptionListenerPass;
类AppBundle扩展了Bundle
{
公共函数生成(ContainerBuilder$container)
{
$container->addCompilerPass(新的例外ListenerPass());
}
}

Symfony 2.7的文档已更新为使用编译器过程:

我想这一变化很快就会进入文档的更高版本

//src/AppBundle/Security/Firewall/ExceptionListener.php
命名空间AppBundle\Security\Firewall;
使用Symfony\Component\HttpFoundation\Request;
使用Symfony\Component\Security\Http\Firewall\ExceptionListener作为BaseExceptionListener;
类ExceptionListener扩展了BaseExceptionListener
{
受保护的函数setTargetPath(请求$Request)
{
//不保存XHR请求的目标路径
//你可以在这里添加任何你想要的逻辑
//请注意,非GET请求已被忽略
如果($request->isXmlHttpRequest()){
返回;
}
父::setTargetPath($request);
}
}
//src/AppBundle/DependencyInjection/Compiler/ExceptionListenerPass.php
命名空间AppBundle\DependencyInjection\Compiler;
使用Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
使用Symfony\Component\DependencyInjection\ContainerBuilder;
使用AppBundle\Security\Firewall\ExceptionListener;
类ExceptionListenerPass实现CompilerPass接口
{
公共函数进程(ContainerBuilder$container)
{
//使用防火墙的名称作为后缀,例如“安全区域”
$definition=$container->getDefinition('security.exception\u listener.securited\u area');
$definition->setClass(异常Listener::class);
}
}
//src/AppBundle/AppBundle.php
名称空间AppBundle;
使用AppBundle\DependencyInjection\Compiler\ExceptionListenerPass;
类AppBundle扩展了Bundle
{
公共函数生成(ContainerBuilder$container)
{
$container->addCompilerPass(新的例外ListenerPass());
}
}

您可以尝试使用Symfony 2.8(目前比3更好。*,作为LTS,至少在3.4推出之前是如此)。只需在composer.json中将“symfony/symfony”的约束替换为“2.8.*”,然后运行composer update,我想这是一个选项,尽管它肯定不吸引人。但他们不可能删除这么重要的功能,是吗?你找到解决方案了吗?我尝试了该问题评论中显示的解决方案,它对我有效。您可以尝试使用Symfony 2.8(目前优于3.*,作为LTS,至少在3.4推出之前是如此)。只需在composer.json中将“symfony/symfony”的约束替换为“2.8.*”,然后运行composer update,我想这是一个选项,尽管它肯定不吸引人。但他们不可能删除这么重要的功能,是吗?你找到解决方案了吗?我尝试了该问题评论中显示的解决方案,它对我有效。不过我更喜欢一个参数。