Symfony seems to register, but not trigger my doctrine event











up vote
1
down vote

favorite












sry if something is not so accurate, but im less experienced with Symfony



I have the following orm mapping:



src/app/ExampleBundle/Resources/config/doctrine/Base.orm.yml

appExampleBundleEntityBase:
type: mappedSuperclass
fields:
createdAt:
type: datetime
nullable: true
options:
default: null
updatedAt:
type: datetime
nullable: true
options:
default: null


This creates a entity Base which i modified to be abstract



src/app/ExampleBundle/Entity/Base.php

abstract class Base {
...
}


I have some other entities they extend this abstract class e.g.



src/app/ExampleBundle/Entity/Category.php

class Category extends Base
{
...
}


Now i tried to add a listener that sets the createdAt/updatedAt datetime on every persist for every entity that extends the Base Entity



src/app/ExampleBundle/EventListener/BaseListener.php

namespace appExampleBundleEventListener;

use DoctrineORMEventLifecycleEventArgs;
use SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorage;
use SymfonyComponentSecurityCoreUserUserInterface;
use appExampleBundleEntityBase;

class BaseListener
{
protected $tokenStorage;

public function __construct(TokenStorage $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

public function prePersist(Base $base, LifecycleEventArgs $event)
{
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof UserInterface) {
$user = null;
}

if ($base->getCreatedAt() === null) {
$base->setCreated($user, new DateTime());
} else {
$base->setUpdated($user, new DateTime());
}
}
}


And added it to the bundles services.yml



src/app/ExampleBundle/Resources/config

services:
appExampleBundleEventListenerBaseListener:
arguments: ['@security.token_storage']
tags:
- { name: doctrine.orm.entity_listener, entity: appExampleBundleEntityBase, event: prePersist }


Symfony throws no Exception, but the defined event seems also not triggered.



I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.



I think, i did everything as it is decribed in the documentation. But it still not working.



The command



debug:event-dispatcher


does also not show the event



So, the question is: What did i wrong?










share|improve this question
























  • entity field, in tags, must refer to Category, not Base
    – SilvioQ
    Nov 21 at 21:00










  • @SilvioQ: 'I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.'
    – Squall
    Nov 21 at 21:04






  • 1




    What version of doctrine are you using? If its < 2.5 you need to specify the listener on the entity as well
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:11










  • @AndreiDumitrescu-Tudor: "^2.5". I tried to set the lifecycleCallbacks, but they try to trigger some method inside the entity
    – Squall
    Nov 21 at 21:16










  • Did you try to set HasLifecycleCallbacks() insise the base entity?
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:28















up vote
1
down vote

favorite












sry if something is not so accurate, but im less experienced with Symfony



I have the following orm mapping:



src/app/ExampleBundle/Resources/config/doctrine/Base.orm.yml

appExampleBundleEntityBase:
type: mappedSuperclass
fields:
createdAt:
type: datetime
nullable: true
options:
default: null
updatedAt:
type: datetime
nullable: true
options:
default: null


This creates a entity Base which i modified to be abstract



src/app/ExampleBundle/Entity/Base.php

abstract class Base {
...
}


I have some other entities they extend this abstract class e.g.



src/app/ExampleBundle/Entity/Category.php

class Category extends Base
{
...
}


Now i tried to add a listener that sets the createdAt/updatedAt datetime on every persist for every entity that extends the Base Entity



src/app/ExampleBundle/EventListener/BaseListener.php

namespace appExampleBundleEventListener;

use DoctrineORMEventLifecycleEventArgs;
use SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorage;
use SymfonyComponentSecurityCoreUserUserInterface;
use appExampleBundleEntityBase;

class BaseListener
{
protected $tokenStorage;

public function __construct(TokenStorage $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

public function prePersist(Base $base, LifecycleEventArgs $event)
{
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof UserInterface) {
$user = null;
}

if ($base->getCreatedAt() === null) {
$base->setCreated($user, new DateTime());
} else {
$base->setUpdated($user, new DateTime());
}
}
}


And added it to the bundles services.yml



src/app/ExampleBundle/Resources/config

services:
appExampleBundleEventListenerBaseListener:
arguments: ['@security.token_storage']
tags:
- { name: doctrine.orm.entity_listener, entity: appExampleBundleEntityBase, event: prePersist }


Symfony throws no Exception, but the defined event seems also not triggered.



I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.



I think, i did everything as it is decribed in the documentation. But it still not working.



The command



debug:event-dispatcher


does also not show the event



So, the question is: What did i wrong?










share|improve this question
























  • entity field, in tags, must refer to Category, not Base
    – SilvioQ
    Nov 21 at 21:00










  • @SilvioQ: 'I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.'
    – Squall
    Nov 21 at 21:04






  • 1




    What version of doctrine are you using? If its < 2.5 you need to specify the listener on the entity as well
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:11










  • @AndreiDumitrescu-Tudor: "^2.5". I tried to set the lifecycleCallbacks, but they try to trigger some method inside the entity
    – Squall
    Nov 21 at 21:16










  • Did you try to set HasLifecycleCallbacks() insise the base entity?
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:28













up vote
1
down vote

favorite









up vote
1
down vote

favorite











sry if something is not so accurate, but im less experienced with Symfony



I have the following orm mapping:



src/app/ExampleBundle/Resources/config/doctrine/Base.orm.yml

appExampleBundleEntityBase:
type: mappedSuperclass
fields:
createdAt:
type: datetime
nullable: true
options:
default: null
updatedAt:
type: datetime
nullable: true
options:
default: null


This creates a entity Base which i modified to be abstract



src/app/ExampleBundle/Entity/Base.php

abstract class Base {
...
}


I have some other entities they extend this abstract class e.g.



src/app/ExampleBundle/Entity/Category.php

class Category extends Base
{
...
}


Now i tried to add a listener that sets the createdAt/updatedAt datetime on every persist for every entity that extends the Base Entity



src/app/ExampleBundle/EventListener/BaseListener.php

namespace appExampleBundleEventListener;

use DoctrineORMEventLifecycleEventArgs;
use SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorage;
use SymfonyComponentSecurityCoreUserUserInterface;
use appExampleBundleEntityBase;

class BaseListener
{
protected $tokenStorage;

public function __construct(TokenStorage $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

public function prePersist(Base $base, LifecycleEventArgs $event)
{
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof UserInterface) {
$user = null;
}

if ($base->getCreatedAt() === null) {
$base->setCreated($user, new DateTime());
} else {
$base->setUpdated($user, new DateTime());
}
}
}


And added it to the bundles services.yml



src/app/ExampleBundle/Resources/config

services:
appExampleBundleEventListenerBaseListener:
arguments: ['@security.token_storage']
tags:
- { name: doctrine.orm.entity_listener, entity: appExampleBundleEntityBase, event: prePersist }


Symfony throws no Exception, but the defined event seems also not triggered.



I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.



I think, i did everything as it is decribed in the documentation. But it still not working.



The command



debug:event-dispatcher


does also not show the event



So, the question is: What did i wrong?










share|improve this question















sry if something is not so accurate, but im less experienced with Symfony



I have the following orm mapping:



src/app/ExampleBundle/Resources/config/doctrine/Base.orm.yml

appExampleBundleEntityBase:
type: mappedSuperclass
fields:
createdAt:
type: datetime
nullable: true
options:
default: null
updatedAt:
type: datetime
nullable: true
options:
default: null


This creates a entity Base which i modified to be abstract



src/app/ExampleBundle/Entity/Base.php

abstract class Base {
...
}


I have some other entities they extend this abstract class e.g.



src/app/ExampleBundle/Entity/Category.php

class Category extends Base
{
...
}


Now i tried to add a listener that sets the createdAt/updatedAt datetime on every persist for every entity that extends the Base Entity



src/app/ExampleBundle/EventListener/BaseListener.php

namespace appExampleBundleEventListener;

use DoctrineORMEventLifecycleEventArgs;
use SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorage;
use SymfonyComponentSecurityCoreUserUserInterface;
use appExampleBundleEntityBase;

class BaseListener
{
protected $tokenStorage;

public function __construct(TokenStorage $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}

public function prePersist(Base $base, LifecycleEventArgs $event)
{
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof UserInterface) {
$user = null;
}

if ($base->getCreatedAt() === null) {
$base->setCreated($user, new DateTime());
} else {
$base->setUpdated($user, new DateTime());
}
}
}


And added it to the bundles services.yml



src/app/ExampleBundle/Resources/config

services:
appExampleBundleEventListenerBaseListener:
arguments: ['@security.token_storage']
tags:
- { name: doctrine.orm.entity_listener, entity: appExampleBundleEntityBase, event: prePersist }


Symfony throws no Exception, but the defined event seems also not triggered.



I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.



I think, i did everything as it is decribed in the documentation. But it still not working.



The command



debug:event-dispatcher


does also not show the event



So, the question is: What did i wrong?







symfony orm event-listener symfony3.4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 22:02

























asked Nov 21 at 20:48









Squall

3818




3818












  • entity field, in tags, must refer to Category, not Base
    – SilvioQ
    Nov 21 at 21:00










  • @SilvioQ: 'I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.'
    – Squall
    Nov 21 at 21:04






  • 1




    What version of doctrine are you using? If its < 2.5 you need to specify the listener on the entity as well
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:11










  • @AndreiDumitrescu-Tudor: "^2.5". I tried to set the lifecycleCallbacks, but they try to trigger some method inside the entity
    – Squall
    Nov 21 at 21:16










  • Did you try to set HasLifecycleCallbacks() insise the base entity?
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:28


















  • entity field, in tags, must refer to Category, not Base
    – SilvioQ
    Nov 21 at 21:00










  • @SilvioQ: 'I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.'
    – Squall
    Nov 21 at 21:04






  • 1




    What version of doctrine are you using? If its < 2.5 you need to specify the listener on the entity as well
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:11










  • @AndreiDumitrescu-Tudor: "^2.5". I tried to set the lifecycleCallbacks, but they try to trigger some method inside the entity
    – Squall
    Nov 21 at 21:16










  • Did you try to set HasLifecycleCallbacks() insise the base entity?
    – Andrei Dumitrescu-Tudor
    Nov 21 at 21:28
















entity field, in tags, must refer to Category, not Base
– SilvioQ
Nov 21 at 21:00




entity field, in tags, must refer to Category, not Base
– SilvioQ
Nov 21 at 21:00












@SilvioQ: 'I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.'
– Squall
Nov 21 at 21:04




@SilvioQ: 'I tried to change the entity param in services to the "real" entity Category, but still no error, nor the event triggered.'
– Squall
Nov 21 at 21:04




1




1




What version of doctrine are you using? If its < 2.5 you need to specify the listener on the entity as well
– Andrei Dumitrescu-Tudor
Nov 21 at 21:11




What version of doctrine are you using? If its < 2.5 you need to specify the listener on the entity as well
– Andrei Dumitrescu-Tudor
Nov 21 at 21:11












@AndreiDumitrescu-Tudor: "^2.5". I tried to set the lifecycleCallbacks, but they try to trigger some method inside the entity
– Squall
Nov 21 at 21:16




@AndreiDumitrescu-Tudor: "^2.5". I tried to set the lifecycleCallbacks, but they try to trigger some method inside the entity
– Squall
Nov 21 at 21:16












Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 at 21:28




Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 at 21:28












2 Answers
2






active

oldest

votes

















up vote
1
down vote













Here the documentation I follow https://symfony.com/doc/3.4/doctrine/event_listeners_subscribers.html



The prePersist method is called for all the entities so you must exclude non instance of appExampleBundleEntityBase. The first argument is LifecycleEventArgs.



public function prePersist(LifecycleEventArgs $event)
{
$base = $event->getObject();
if (!$base instanceof Base) {
return;
}
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof UserInterface) {
$user = null;
}

if ($base->getCreatedAt() === null) {
$base->setCreated($user, new DateTime());
} else {
$base->setUpdated($user, new DateTime());
}
}


I can recommend you StofDoctrineExtensionsBundle (Timestampable) that does exactly what you want. It based on DoctrineExtensions.



There is even a trait that works like a charm.






share|improve this answer























  • Where does $args come from?
    – cezar
    Nov 21 at 21:52










  • My Problem is that the prePersist Method does never run. I tried to throw Exception or die() inside the prePersist method, but nothing is called. And thanks for Link to the StofBundle, i will take a look at it.
    – Squall
    Nov 21 at 21:59










  • @cezar typo... I edit the post
    – EquaPro
    Nov 21 at 22:01






  • 2




    May be, you must change the tag name to doctrine.event_listener (without orm). entity property is not necesary.
    – SilvioQ
    Nov 21 at 22:08












  • @SilvioQ +1 I missed the tag name
    – EquaPro
    Nov 21 at 22:24


















up vote
0
down vote













After some research, many more tests, diving into the EntityManager and the UnitOfWork. Nothing seems to work fine. I get it so far to work on doctrine:fixtures:load, but for any reason they still not working if i use the entity manager in the Controllers. So, i decided to try another way with a subscriber.



tags:
- { name: doctrine.event_subscriber }

class ... implements EventSubscriber


So i still dont know why the Listener did not work as expected, but with the subscribers i found a solution that does.



Thanks to all of you for support :)






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420251%2fsymfony-seems-to-register-but-not-trigger-my-doctrine-event%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Here the documentation I follow https://symfony.com/doc/3.4/doctrine/event_listeners_subscribers.html



    The prePersist method is called for all the entities so you must exclude non instance of appExampleBundleEntityBase. The first argument is LifecycleEventArgs.



    public function prePersist(LifecycleEventArgs $event)
    {
    $base = $event->getObject();
    if (!$base instanceof Base) {
    return;
    }
    $user = $this->tokenStorage->getToken()->getUser();
    if (!$user instanceof UserInterface) {
    $user = null;
    }

    if ($base->getCreatedAt() === null) {
    $base->setCreated($user, new DateTime());
    } else {
    $base->setUpdated($user, new DateTime());
    }
    }


    I can recommend you StofDoctrineExtensionsBundle (Timestampable) that does exactly what you want. It based on DoctrineExtensions.



    There is even a trait that works like a charm.






    share|improve this answer























    • Where does $args come from?
      – cezar
      Nov 21 at 21:52










    • My Problem is that the prePersist Method does never run. I tried to throw Exception or die() inside the prePersist method, but nothing is called. And thanks for Link to the StofBundle, i will take a look at it.
      – Squall
      Nov 21 at 21:59










    • @cezar typo... I edit the post
      – EquaPro
      Nov 21 at 22:01






    • 2




      May be, you must change the tag name to doctrine.event_listener (without orm). entity property is not necesary.
      – SilvioQ
      Nov 21 at 22:08












    • @SilvioQ +1 I missed the tag name
      – EquaPro
      Nov 21 at 22:24















    up vote
    1
    down vote













    Here the documentation I follow https://symfony.com/doc/3.4/doctrine/event_listeners_subscribers.html



    The prePersist method is called for all the entities so you must exclude non instance of appExampleBundleEntityBase. The first argument is LifecycleEventArgs.



    public function prePersist(LifecycleEventArgs $event)
    {
    $base = $event->getObject();
    if (!$base instanceof Base) {
    return;
    }
    $user = $this->tokenStorage->getToken()->getUser();
    if (!$user instanceof UserInterface) {
    $user = null;
    }

    if ($base->getCreatedAt() === null) {
    $base->setCreated($user, new DateTime());
    } else {
    $base->setUpdated($user, new DateTime());
    }
    }


    I can recommend you StofDoctrineExtensionsBundle (Timestampable) that does exactly what you want. It based on DoctrineExtensions.



    There is even a trait that works like a charm.






    share|improve this answer























    • Where does $args come from?
      – cezar
      Nov 21 at 21:52










    • My Problem is that the prePersist Method does never run. I tried to throw Exception or die() inside the prePersist method, but nothing is called. And thanks for Link to the StofBundle, i will take a look at it.
      – Squall
      Nov 21 at 21:59










    • @cezar typo... I edit the post
      – EquaPro
      Nov 21 at 22:01






    • 2




      May be, you must change the tag name to doctrine.event_listener (without orm). entity property is not necesary.
      – SilvioQ
      Nov 21 at 22:08












    • @SilvioQ +1 I missed the tag name
      – EquaPro
      Nov 21 at 22:24













    up vote
    1
    down vote










    up vote
    1
    down vote









    Here the documentation I follow https://symfony.com/doc/3.4/doctrine/event_listeners_subscribers.html



    The prePersist method is called for all the entities so you must exclude non instance of appExampleBundleEntityBase. The first argument is LifecycleEventArgs.



    public function prePersist(LifecycleEventArgs $event)
    {
    $base = $event->getObject();
    if (!$base instanceof Base) {
    return;
    }
    $user = $this->tokenStorage->getToken()->getUser();
    if (!$user instanceof UserInterface) {
    $user = null;
    }

    if ($base->getCreatedAt() === null) {
    $base->setCreated($user, new DateTime());
    } else {
    $base->setUpdated($user, new DateTime());
    }
    }


    I can recommend you StofDoctrineExtensionsBundle (Timestampable) that does exactly what you want. It based on DoctrineExtensions.



    There is even a trait that works like a charm.






    share|improve this answer














    Here the documentation I follow https://symfony.com/doc/3.4/doctrine/event_listeners_subscribers.html



    The prePersist method is called for all the entities so you must exclude non instance of appExampleBundleEntityBase. The first argument is LifecycleEventArgs.



    public function prePersist(LifecycleEventArgs $event)
    {
    $base = $event->getObject();
    if (!$base instanceof Base) {
    return;
    }
    $user = $this->tokenStorage->getToken()->getUser();
    if (!$user instanceof UserInterface) {
    $user = null;
    }

    if ($base->getCreatedAt() === null) {
    $base->setCreated($user, new DateTime());
    } else {
    $base->setUpdated($user, new DateTime());
    }
    }


    I can recommend you StofDoctrineExtensionsBundle (Timestampable) that does exactly what you want. It based on DoctrineExtensions.



    There is even a trait that works like a charm.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 21 at 22:00

























    answered Nov 21 at 21:31









    EquaPro

    1012




    1012












    • Where does $args come from?
      – cezar
      Nov 21 at 21:52










    • My Problem is that the prePersist Method does never run. I tried to throw Exception or die() inside the prePersist method, but nothing is called. And thanks for Link to the StofBundle, i will take a look at it.
      – Squall
      Nov 21 at 21:59










    • @cezar typo... I edit the post
      – EquaPro
      Nov 21 at 22:01






    • 2




      May be, you must change the tag name to doctrine.event_listener (without orm). entity property is not necesary.
      – SilvioQ
      Nov 21 at 22:08












    • @SilvioQ +1 I missed the tag name
      – EquaPro
      Nov 21 at 22:24


















    • Where does $args come from?
      – cezar
      Nov 21 at 21:52










    • My Problem is that the prePersist Method does never run. I tried to throw Exception or die() inside the prePersist method, but nothing is called. And thanks for Link to the StofBundle, i will take a look at it.
      – Squall
      Nov 21 at 21:59










    • @cezar typo... I edit the post
      – EquaPro
      Nov 21 at 22:01






    • 2




      May be, you must change the tag name to doctrine.event_listener (without orm). entity property is not necesary.
      – SilvioQ
      Nov 21 at 22:08












    • @SilvioQ +1 I missed the tag name
      – EquaPro
      Nov 21 at 22:24
















    Where does $args come from?
    – cezar
    Nov 21 at 21:52




    Where does $args come from?
    – cezar
    Nov 21 at 21:52












    My Problem is that the prePersist Method does never run. I tried to throw Exception or die() inside the prePersist method, but nothing is called. And thanks for Link to the StofBundle, i will take a look at it.
    – Squall
    Nov 21 at 21:59




    My Problem is that the prePersist Method does never run. I tried to throw Exception or die() inside the prePersist method, but nothing is called. And thanks for Link to the StofBundle, i will take a look at it.
    – Squall
    Nov 21 at 21:59












    @cezar typo... I edit the post
    – EquaPro
    Nov 21 at 22:01




    @cezar typo... I edit the post
    – EquaPro
    Nov 21 at 22:01




    2




    2




    May be, you must change the tag name to doctrine.event_listener (without orm). entity property is not necesary.
    – SilvioQ
    Nov 21 at 22:08






    May be, you must change the tag name to doctrine.event_listener (without orm). entity property is not necesary.
    – SilvioQ
    Nov 21 at 22:08














    @SilvioQ +1 I missed the tag name
    – EquaPro
    Nov 21 at 22:24




    @SilvioQ +1 I missed the tag name
    – EquaPro
    Nov 21 at 22:24












    up vote
    0
    down vote













    After some research, many more tests, diving into the EntityManager and the UnitOfWork. Nothing seems to work fine. I get it so far to work on doctrine:fixtures:load, but for any reason they still not working if i use the entity manager in the Controllers. So, i decided to try another way with a subscriber.



    tags:
    - { name: doctrine.event_subscriber }

    class ... implements EventSubscriber


    So i still dont know why the Listener did not work as expected, but with the subscribers i found a solution that does.



    Thanks to all of you for support :)






    share|improve this answer

























      up vote
      0
      down vote













      After some research, many more tests, diving into the EntityManager and the UnitOfWork. Nothing seems to work fine. I get it so far to work on doctrine:fixtures:load, but for any reason they still not working if i use the entity manager in the Controllers. So, i decided to try another way with a subscriber.



      tags:
      - { name: doctrine.event_subscriber }

      class ... implements EventSubscriber


      So i still dont know why the Listener did not work as expected, but with the subscribers i found a solution that does.



      Thanks to all of you for support :)






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        After some research, many more tests, diving into the EntityManager and the UnitOfWork. Nothing seems to work fine. I get it so far to work on doctrine:fixtures:load, but for any reason they still not working if i use the entity manager in the Controllers. So, i decided to try another way with a subscriber.



        tags:
        - { name: doctrine.event_subscriber }

        class ... implements EventSubscriber


        So i still dont know why the Listener did not work as expected, but with the subscribers i found a solution that does.



        Thanks to all of you for support :)






        share|improve this answer












        After some research, many more tests, diving into the EntityManager and the UnitOfWork. Nothing seems to work fine. I get it so far to work on doctrine:fixtures:load, but for any reason they still not working if i use the entity manager in the Controllers. So, i decided to try another way with a subscriber.



        tags:
        - { name: doctrine.event_subscriber }

        class ... implements EventSubscriber


        So i still dont know why the Listener did not work as expected, but with the subscribers i found a solution that does.



        Thanks to all of you for support :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 12:58









        Squall

        3818




        3818






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420251%2fsymfony-seems-to-register-but-not-trigger-my-doctrine-event%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo