Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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 symfony 5,生命周期侦听器未运行_Php_Symfony - Fatal编程技术网

Php symfony 5,生命周期侦听器未运行

Php symfony 5,生命周期侦听器未运行,php,symfony,Php,Symfony,我尝试侦听器创建的生命周期,但他不执行转储。 我已经创建了一个实体、一个侦听器和更新服务.yml 这太疯狂了;-) 我有: in services.yaml App\EventListener\TestOrmListener: tags: - { name: doctrineormtester,event: postPersist, entity: 'App\Entity\Galery'} 在src/EventListener/TestOrmListener.php中

我尝试侦听器创建的生命周期,但他不执行转储。 我已经创建了一个实体、一个侦听器和更新服务.yml

这太疯狂了;-)

我有: in services.yaml

  App\EventListener\TestOrmListener:
    tags:
      - { name: doctrineormtester,event: postPersist, entity: 'App\Entity\Galery'}
在src/EventListener/TestOrmListener.php中

<?php
namespace App\EventListener;

use App\Entity\Galery;
use Doctrine\Persistence\Event\LifecycleEventArgs;

class TestOrmListener
{
    // the listener methods receive an argument which gives you access to
    // both the entity object of the event and the entity manager itself
    public function postPersist(LifecycleEventArgs $args): void
    {
        $entity = $args->getObject();

        // if this listener only applies to certain entity types,
        // add some code to check the entity type as early as possible
        if (!$entity instanceof Galery) {
            return;
        }

        $entityManager = $args->getObjectManager();
        dump($entityManager);
        die('mick');
        // ... do something with the Product entity
    }
}

您的标记部分有问题。
据这位官员说:

下一步是通过为Symfony应用程序创建一个新服务并使用Doctrine.event\u listener标记对其进行标记,从而在Symfony应用程序中启用Doctrine侦听器

因此,您的服务定义应该如下所示:

App\EventListener\TestOrmListener:
        tags:
            - { name: 'doctrine.event_listener', event: 'postPersist', entity: 'App\Entity\Galery' }

您的标记部分有问题。 据这位官员说:

下一步是通过为Symfony应用程序创建一个新服务并使用Doctrine.event\u listener标记对其进行标记,从而在Symfony应用程序中启用Doctrine侦听器

因此,您的服务定义应该如下所示:

App\EventListener\TestOrmListener:
        tags:
            - { name: 'doctrine.event_listener', event: 'postPersist', entity: 'App\Entity\Galery' }

我猜您的侦听器标记中有一个输入错误。我在services.yaml中有一个错误。但是侦听器没有运行尝试修复您的侦听器标记定义,这可能有助于触发您的侦听器的生命周期事件。-{name:'doctrine.orm.entity_listener',event:'postPersist',entity:'App\entity\Galery'}@eldino以及它是如何结束的?我的回答有用吗,还是你找到了另一个解决方案?请给未来的读者留下一些回复。好的,我写一条评论,谢谢。我想你的侦听器标记有一个输入错误。我在服务中有一个错误。yaml但是侦听器没有运行尝试修复你的侦听器标记定义,这可能有助于触发你的侦听器的生命周期事件。-{name:'doctrine.orm.entity_listener',event:'postPersist',entity:'App\entity\Galery'}@eldino以及它是如何结束的?我的回答有用吗,还是你找到了另一个解决方案?请给未来的读者留下一些回复。好的,我写了一条评论,谢谢。我也在我自己的项目(与你的听众)上测试了它,它工作了好的,我的docker中有一个错误。我也在我自己的项目(与你的听众)上测试了它,它工作了好的,我的docker中有一个错误。