Symfony seems to register, but not trigger my doctrine event
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
|
show 1 more comment
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
entity field, in tags, must refer toCategory
, notBase
– SilvioQ
Nov 21 '18 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 '18 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 '18 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 '18 at 21:16
Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 '18 at 21:28
|
show 1 more comment
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
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
symfony orm event-listener symfony3.4
edited Nov 21 '18 at 22:02
Squall
asked Nov 21 '18 at 20:48
SquallSquall
3818
3818
entity field, in tags, must refer toCategory
, notBase
– SilvioQ
Nov 21 '18 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 '18 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 '18 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 '18 at 21:16
Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 '18 at 21:28
|
show 1 more comment
entity field, in tags, must refer toCategory
, notBase
– SilvioQ
Nov 21 '18 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 '18 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 '18 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 '18 at 21:16
Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 '18 at 21:28
entity field, in tags, must refer to
Category
, not Base
– SilvioQ
Nov 21 '18 at 21:00
entity field, in tags, must refer to
Category
, not Base
– SilvioQ
Nov 21 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 21:16
Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 '18 at 21:28
Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 '18 at 21:28
|
show 1 more comment
2 Answers
2
active
oldest
votes
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.
Where does$args
come from?
– cezar
Nov 21 '18 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 '18 at 21:59
@cezar typo... I edit the post
– EquaPro
Nov 21 '18 at 22:01
2
May be, you must change the tag name todoctrine.event_listener
(without orm).entity
property is not necesary.
– SilvioQ
Nov 21 '18 at 22:08
@SilvioQ +1 I missed the tag name
– EquaPro
Nov 21 '18 at 22:24
|
show 2 more comments
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 :)
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Where does$args
come from?
– cezar
Nov 21 '18 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 '18 at 21:59
@cezar typo... I edit the post
– EquaPro
Nov 21 '18 at 22:01
2
May be, you must change the tag name todoctrine.event_listener
(without orm).entity
property is not necesary.
– SilvioQ
Nov 21 '18 at 22:08
@SilvioQ +1 I missed the tag name
– EquaPro
Nov 21 '18 at 22:24
|
show 2 more comments
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.
Where does$args
come from?
– cezar
Nov 21 '18 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 '18 at 21:59
@cezar typo... I edit the post
– EquaPro
Nov 21 '18 at 22:01
2
May be, you must change the tag name todoctrine.event_listener
(without orm).entity
property is not necesary.
– SilvioQ
Nov 21 '18 at 22:08
@SilvioQ +1 I missed the tag name
– EquaPro
Nov 21 '18 at 22:24
|
show 2 more comments
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.
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.
edited Nov 21 '18 at 22:00
answered Nov 21 '18 at 21:31
EquaProEquaPro
1794
1794
Where does$args
come from?
– cezar
Nov 21 '18 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 '18 at 21:59
@cezar typo... I edit the post
– EquaPro
Nov 21 '18 at 22:01
2
May be, you must change the tag name todoctrine.event_listener
(without orm).entity
property is not necesary.
– SilvioQ
Nov 21 '18 at 22:08
@SilvioQ +1 I missed the tag name
– EquaPro
Nov 21 '18 at 22:24
|
show 2 more comments
Where does$args
come from?
– cezar
Nov 21 '18 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 '18 at 21:59
@cezar typo... I edit the post
– EquaPro
Nov 21 '18 at 22:01
2
May be, you must change the tag name todoctrine.event_listener
(without orm).entity
property is not necesary.
– SilvioQ
Nov 21 '18 at 22:08
@SilvioQ +1 I missed the tag name
– EquaPro
Nov 21 '18 at 22:24
Where does
$args
come from?– cezar
Nov 21 '18 at 21:52
Where does
$args
come from?– cezar
Nov 21 '18 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 '18 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 '18 at 21:59
@cezar typo... I edit the post
– EquaPro
Nov 21 '18 at 22:01
@cezar typo... I edit the post
– EquaPro
Nov 21 '18 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 '18 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 '18 at 22:08
@SilvioQ +1 I missed the tag name
– EquaPro
Nov 21 '18 at 22:24
@SilvioQ +1 I missed the tag name
– EquaPro
Nov 21 '18 at 22:24
|
show 2 more comments
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 :)
add a comment |
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 :)
add a comment |
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 :)
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 :)
answered Nov 23 '18 at 12:58
SquallSquall
3818
3818
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
entity field, in tags, must refer to
Category
, notBase
– SilvioQ
Nov 21 '18 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 '18 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 '18 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 '18 at 21:16
Did you try to set HasLifecycleCallbacks() insise the base entity?
– Andrei Dumitrescu-Tudor
Nov 21 '18 at 21:28