Blog

How to use the Doctrine ORM to persist data in eZ Publish 5.3

This is a short outline of how to use the Doctrine ORM to persist data in eZ Publish 5.3. Frankly, it took me more than a day to figure it out...

Please correct me if I did something stupid here, I found zero resources for it so far...

First you need the Doctrine ORM and the Instantiator. You can get them with composer.

php -d memory_limit=-1 composer.phar require doctrine/instantiator:1.0.* doctrine/orm:2.4.*

Then edit your 'ezpublish/config/ezpublish.yml' and add this to get a default entity manager:

doctrine:
    orm:
        auto_mapping: true
        default_entity_manager: default

Now you can create an Entity like my "ContactMessage" and persist it in a Controller like in Symfony:

$contactMessage = new ContactMessage();
$contactMessage->setName( 'my name' );

$em = $this->getDoctrine()->getManager();
$em->persist( $contactMessage );
$em->flush();

I hope this helps people that are struggling like me with the "transition" from the legacy stack to the "new world" of Symfony inside eZ Publish.

blog comments powered by Disqus