ReflectionException在RegisterListenersPass.php第101行:类不存在Symfony 2
这是我的第一个问题,我在RegisterListenersPass.php第101行有这个错误ReflectionException:Class Acme \ exampleBundle \ Handler \ AuthenticationHandler.php不存在。我使用FOSUserBundle和Symfony的2ReflectionException在RegisterListenersPass.php第101行:类不存在Symfony 2
services.xml中
<service id="login_listener" class="%vixur.login_listener.class%">
<tag name="kernel.event_subscriber"/>
</service>
AuthenticationHandler.php:
<?php
namespace acme\exampleBundle\Handler;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Listener responsible to change the redirection at the end of the password resetting
*/
class AuthenticationHandler implements EventSubscriberInterface
{
private $container;
public function __construct()
{
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::SECURITY_IMPLICIT_LOGIN => 'onSecurityImplicitLogin',
);
}
public function onSecurityImplicitLogin(FormEvent $event)
{
$url = $this->router->generate('ex_homepage');
$event->setResponse(new RedirectResponse($url));
}
}
谢谢!
您确定名称空间是否正确?请小心,因为您必须尝试关注Symfony coding standar(PSR-0和PSR-4),并且文件夹的名称并不严格。必须是CamelCase。
您是否检查%vixur.login_listener.class%变量是否具有正确的值?
感谢您的快速响应,文件夹名称因隐私问题而更改,但我确信命名空间是正确的,我也向此文件复制了另一个侦听器,但它也不起作用。 –
您是否在代码中看到过您尝试使用不存在的路由器变量? –
我真的认为路径文件夹或类名或您在变量中存储的FQN有问题。 –
我只是遇到了同样的情况,最终发现了PHPStorm格式化正在改变XML来这样的事情
<parameters>
<parameter key="vixur.login_listener.class">
Vixur\LoginListener
</parameter>
</parameters>
,而应该是
<parameters>
<parameter key="vixur.login_listener.class">Vixur\LoginListener</parameter>
</parameters>
'Acme的!== acme'。你的命名空间是不同的,它正在寻找'Acme \ exampleBundle',但你的实际命名空间是'acme \ exampleBundle'。 – qooplmao