@@ -291,7 +291,7 @@ can control. The following configuration options exist for a mapping:
291291- ``dir `` Path to the mapping or entity files (depending on the driver). If
292292 this path is relative it is assumed to be relative to the bundle root. This
293293 only works if the name of your mapping is a bundle name. If you want to use
294- this option to specifiy absolute paths you should prefix the path with the
294+ this option to specify absolute paths you should prefix the path with the
295295 kernel parameters that exist in the DIC (for example %kernel.root_dir%).
296296- ``prefix `` A common namespace prefix that all entities of this mapping
297297 share. This prefix should never conflict with prefixes of other defined
@@ -341,44 +341,6 @@ The following configuration shows a bunch of mapping examples:
341341 prefix : DoctrineExtensions\Entity\
342342 alias : DExt
343343
344- Registering Event Listeners and Subscribers
345- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
346-
347- Doctrine uses the lightweight ``Doctrine\Common\EventManager `` class to trigger
348- a number of different events which you can hook into. You can register Event
349- Listeners or Subscribers by tagging the respective services with
350- ``doctrine.dbal.<connection>_event_listener `` or
351- ``doctrine.dbal.<connection>_event_subscriber `` using the Dependency Injection
352- container.
353-
354- You have to use the name of the DBAL connection to clearly identify which
355- connection the listeners should be registered with. If you are using multiple
356- connections you can hook different events into each connection.
357-
358- .. code-block :: xml
359-
360- <container xmlns =" http://symfony.com/schema/dic/services"
361- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
362- xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
363-
364- <services >
365-
366- <service id =" doctrine.extensions.versionable_listener" class =" DoctrineExtensions\Versionable\VersionableListener" >
367- <tag name =" doctrine.dbal.default_event_subscriber" />
368- </service >
369-
370- <service id =" mybundle.doctrine.mylistener" class =" MyBundle\Doctrine\MyListener" >
371- <tag name =" doctrine.dbal.default_event_listener" event =" prePersist" />
372- </service >
373-
374- </services >
375-
376- </container >
377-
378- Although the Event Listener and Subscriber tags are prefixed with ``doctrine.dbal ``
379- these tags also work for the ORM events. Internally Doctrine re-uses the EventManager
380- that is registered with the connection for the ORM.
381-
382344 Multiple Entity Managers
383345~~~~~~~~~~~~~~~~~~~~~~~~
384346
@@ -425,18 +387,50 @@ retrieve it from the Symfony Dependency Injection Container::
425387The service ``doctrine.orm.entity_manager `` is an alias for the default entity
426388manager defined in the ``default_entity_manager `` configuration option.
427389
390+ Registering Event Listeners and Subscribers
391+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
392+
393+
394+ .. code-block :: xml
395+
396+ <container xmlns =" http://symfony.com/schema/dic/services"
397+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
398+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
399+
400+ <services >
401+
402+ <service id =" doctrine.extensions.versionable_listener" class =" DoctrineExtensions\Versionable\VersionableListener" >
403+ <tag name =" doctrine.dbal.default_event_subscriber" />
404+ </service >
405+
406+ <service id =" mybundle.doctrine.mylistener" class =" MyBundle\Doctrine\MyListener" >
407+ <tag name =" doctrine.dbal.default_event_listener" event =" prePersist" />
408+ </service >
409+
410+ </services >
411+
412+ </container >
413+
414+ Although the Event Listener and Subscriber tags are prefixed with ``doctrine.dbal ``
415+ these tags also work for the ORM events. Internally Doctrine re-uses the EventManager
416+ that is registered with the connection for the ORM.
417+
428418.. _doctrine-event-config :
429419
430420Registering Event Listeners and Subscribers
431421~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
432422
433- Doctrine ships with an event system that allows to hook into many different
434- events happening during the lifecycle of entities or at other occasions.
423+ Doctrine uses the lightweight ``Doctrine\Common\EventManager `` class to
424+ trigger a number of different events which you can hook into. You can register
425+ Event Listeners or Subscribers by tagging the respective services with
426+ ``doctrine.event_listener `` or ``doctrine.event_subscriber `` using the service
427+ container.
435428
436- To register services to act as event listeners or subscribers (listeners from here)
437- you have to tag them with the appropriate names. Depending on your use-case you can hook
438- a listener into every DBAL Connection and ORM Entity Manager or just into one
439- specific DBAL connection and all the EntityManagers that use this connection.
429+ To register services to act as event listeners or subscribers (listeners from
430+ here) you have to tag them with the appropriate names. Depending on your
431+ use-case you can hook a listener into every DBAL Connection and ORM Entity
432+ Manager or just into one specific DBAL connection and all the EntityManagers
433+ that use this connection.
440434
441435.. configuration-block ::
442436
@@ -454,15 +448,15 @@ specific DBAL connection and all the EntityManagers that use this connection.
454448 my.listener :
455449 class : MyEventListener
456450 tags :
457- - { name: doctrine.common. event_listener }
451+ - { name: doctrine.event_listener }
458452 my.listener2 :
459453 class : MyEventListener2
460454 tags :
461- - { name: doctrine.dbal.default_event_listener }
455+ - { name: doctrine.event_listener, connection: default }
462456 my.subscriber :
463457 class : MyEventSubscriber
464458 tags :
465- - { name: doctrine.dbal.default_event_subscriber }
459+ - { name: doctrine.event_subscriber, connection: default }
466460
467461 .. code-block :: xml
468462
@@ -478,13 +472,13 @@ specific DBAL connection and all the EntityManagers that use this connection.
478472
479473 <services >
480474 <service id =" my.listener" class =" MyEventListener" >
481- <tag name =" doctrine.common. event_listener" />
475+ <tag name =" doctrine.event_listener" />
482476 </service >
483477 <service id =" my.listener2" class =" MyEventListener2" >
484- <tag name =" doctrine.dbal.default_event_listener " />
478+ <tag name =" doctrine.event_listener " connection = " default " />
485479 </service >
486480 <service id =" my.subscriber" class =" MyEventSubscriber" >
487- <tag name =" doctrine.dbal.default_event_subscriber " />
481+ <tag name =" doctrine.event_subscriber " connection = " default " />
488482 </service >
489483 </services >
490484 </container >
@@ -552,34 +546,24 @@ types such as strings, integers and fields. However you can also integrate
552546them nicely with associations.
553547
554548This is done by the help of a dedicated field:
555- :class: `Symfony\\ Component \\ Form\\ EntityChoiceField `. It provides a list of
549+ :class: `Symfony\\ Bridge \\ Doctrine \\ Form\\ Type \\ EntityType `. It provides a list of
556550choices from which an entity can be selected.
557551
558552.. code-block :: php
559553
560- use Symfony\Component\ Form\EntityChoiceField ;
554+ use Symfony\Bridge\Doctrine\ Form\Type\EntityType ;
561555
562- $field = new EntityChoiceField('users', array(
563- 'em' => $em,
564- 'class' => 'Acme\\HelloBundle\\Entity\\User',
565- 'property' => 'username',
566- 'query_builder' => $qb,
556+ $builder->add('users','entity',
557+ array('class' => 'Acme\\HelloBundle\\Entity\\User',
567558 ));
568559
569- $form->addField($field);
570-
571- The 'em' option expects the EntityManager, the 'class' option expects the Entity
572- class name as an argument. The optional 'property' option allows you to choose
573- the property used to display the entity (``__toString `` will be used if not
574- set). The optional 'query_builder' option expects a ``QueryBuilder `` instance or
560+ The required 'class' option expects the Entity class name as an argument.
561+ The optional 'property' option allows you to choose the property used to
562+ display the entity (``__toString `` will be used if not set).
563+ The optional 'query_builder' option expects a ``QueryBuilder `` instance or
575564a closure receiving the repository as an argument and returning the QueryBuilder
576565used to get the choices. If not set all entities will be used.
577566
578- .. tip ::
579-
580- ``EntityChoiceField `` extends :class: `Symfony\\ Component\\ Form\\ ChoiceField `
581- so you can also give the array of choices with the 'choices' option instead
582- of using a QueryBuilder.
583567
584568.. _documentation : http://www.doctrine-project.org/docs/orm/2.0/en
585569.. _Doctrine : http://www.doctrine-project.org
0 commit comments