Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';用FOSUserBundle捕获条令事件_Php_Symfony_Doctrine Orm_Fosuserbundle - Fatal编程技术网

Php Can';用FOSUserBundle捕获条令事件

Php Can';用FOSUserBundle捕获条令事件,php,symfony,doctrine-orm,fosuserbundle,Php,Symfony,Doctrine Orm,Fosuserbundle,我试图在提交个人资料表单时捕捉任何条令事件。我的活动如下所示: testevent: class: AppBundle\Event\TestListener arguments: ['@service_container'] tags: - { name: doctrine.event_subscriber } - { name: doctrine.event_listener, event: prePersist, method: prePers

我试图在提交个人资料表单时捕捉任何条令事件。我的活动如下所示:

testevent:
    class: AppBundle\Event\TestListener
    arguments: ['@service_container']
    tags:
      - { name: doctrine.event_subscriber }
      - { name: doctrine.event_listener, event: prePersist, method: prePersist, connection: default }
以及我的事件,目前应记录并退出应用程序,同时转储当前实体:

class TestListener implements EventSubscriber
{
    private $container;

    public function __construct(\Symfony\Component\DependencyInjection\Container $container)
    {
        $this->container = $container;
    }

    public function prePersist(\Doctrine\ORM\Event\LifecycleEventArgs $args){
        $entity = $args->getEntity();
        $this->container->get('logger')->info('asdasd');
        echo '<pre>';
        \Doctrine\Common\Util\Debug::dump($entity); exit;
        echo '</pre>';

    }

    public function getSubscribedEvents()
    {
        return array(
            'onPrePersist'

        );
    }
}  
那是

<service id="fos_user.object_manager" class="Doctrine\Common\Persistence\ObjectManager" public="false">
    <argument>%fos_user.model_manager_name%</argument>
</service>
对象管理器在包中声明如下:


%fos\u用户、型号\u管理器\u名称%

可能是这位经理没有召集条令事件吗?我怎样才能打电话给他们?

为什么你要把你的
TestListener
注册为订户和监听器?我想你想要的只是订阅者,所以删除
-{name:doctrine.event\u listener,event:prePersist,method:prePersist,connection:default}
并且在你的
getSubscribedEvents()
方法中,事件
onPrePersist
是不正确的,即使有这些更改,它仍然不起作用。它只在我在其他地方显式调用persist时起作用,但在这里修改配置文件时不会触发。可能您的订户是在FOSUserBundle之后注册的?尝试在FOSUserBundle之前移动AppKernel中的捆绑包?该捆绑包已在FOSUB之前。为什么尝试将您的
TestListener
注册为订户和侦听器?我想你想要的只是订阅者,所以删除
-{name:doctrine.event\u listener,event:prePersist,method:prePersist,connection:default}
并且在你的
getSubscribedEvents()
方法中,事件
onPrePersist
是不正确的,即使有这些更改,它仍然不起作用。它只在我在其他地方显式调用persist时起作用,但在这里修改配置文件时不会触发。可能您的订户是在FOSUserBundle之后注册的?尝试在FOSUserBundle之前移动AppKernel中的捆绑包?该捆绑包已在FOSUB之前。
public function updateUser(UserInterface $user, $andFlush = true)
{
    $this->updateCanonicalFields($user);
    $this->updatePassword($user);

    $this->objectManager->persist($user);
    if ($andFlush) {
        $this->objectManager->flush();
    }
}
<service id="fos_user.object_manager" class="Doctrine\Common\Persistence\ObjectManager" public="false">
    <argument>%fos_user.model_manager_name%</argument>
</service>