Update docs/en/reference/events.rst
Docs for lifecycle-callback event arg
This commit is contained in:
parent
7177306536
commit
76c4be1b74
@ -336,6 +336,30 @@ The ``key`` of the lifecycleCallbacks is the name of the method and
|
|||||||
the value is the event type. The allowed event types are the ones
|
the value is the event type. The allowed event types are the ones
|
||||||
listed in the previous Lifecycle Events section.
|
listed in the previous Lifecycle Events section.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
|
Lifecycle Callbacks Event Argument
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
Since 2.4 the triggered event is given to the lifecycle-callback.
|
||||||
|
|
||||||
|
With the additional argument you have access to the
|
||||||
|
``EntityManager`` and ``UnitOfWork`` APIs inside these callback methods.
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// ...
|
||||||
|
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
public function preUpdate(PreUpdateEventArgs $event)
|
||||||
|
{
|
||||||
|
if ($event->hasChangedField('username')) {
|
||||||
|
// Do something when the username is changed.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Listening to Lifecycle Events
|
Listening to Lifecycle Events
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user