eZ Community » Blogs » Patrizio Bekerle » How to use the Doctrine ORM to...

By

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

Tuesday 02 September 2014 2:23:30 pm

  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

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.

Proudly Developed with from