Doctrine: Entity listeners reference
7 August 2022 (Updated 7 August 2022)
On this page
Register entity listener
Map the entity listener class using annotations.
<?php
namespace MyProject\Entity;
use App\EventListener\UserListener;
#[Entity]
#[EntityListeners([UserListener::class])]
class User
{
// ....
}
Define entity listener
<?php
use Doctrine\ORM\Event\PreUpdateEventArgs;
class UserListener
{
public function preUpdate(User $user, PreUpdateEventArgs $event)
{
// Do something on pre update.
}
}
Other notes
- An entity listener is invoked just for an entity, as opposed to Doctrine events which are invoked for all entities.
Sources
Tagged:
Doctrine
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment