Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

175 lines (132 sloc) 5.91 kb

Doctrine PHPCR Bundle

This bundle integrates Doctrine PHPCR ODM and PHPCR backends into Symfony2 like:


Follow the installation tutorial


The configuration is similar to Doctrine ORM and MongoDB configuration for Symfony2 as its based on the AbstractDoctrineBundle as well:

    # configure the PHPCR session
            ## backend type: jackrabbit, doctrinedbal or midgard
            type: jackrabbit

            ## doctrinedbal only, required
            connection: <service name of the doctrine dbal connection>

            ## jackrabbit only, required
            url: http://localhost:8080/server/
            ## jackrabbit only, optional. see
            default_header: ...
            expect: 'Expect: 100-continue'

            ## tweak options for jackrabbit and doctrinedbal (all jackalope versions)
            # optional, below set to the default
            # enable if you want to have an exception right away if backend login fails
            check_login_on_server: false
            # enable if you experience segmentation faults while working with binary data in documents
            disable_stream_wrapper: false
            # enable if you do not want to use transactions and you neither want the odm to automatically use transactions
            # its highly recommended NOT to disable transactions
            disable_transactions: false
        workspace: default
        username: admin
        password: admin
        # not all backends support options
            'jackalope.fetch_depth': 1
    # enable the ODM layer. omit the odm section if you only want a phpcr session but no odm
        auto_mapping: true
        # whether to automatically create proxy classes or create them manually
        auto_generate_proxy_classes: %kernel.debug%
        # overwrite the default location for generated proxies
        proxy_dir: ...
        # overwrite the default php namespace for proxies
        proxy_namespace: ...
        # set the language fallback order (for translatable documents)
                - en
                - de
                - fr
                - de
                - en
                - fr
                - fr
                - en
                - de

Configuration for Midgard2 PHPCR provider

To use DoctrinePHPCRBundle with the Midgard2 PHPCR provider, you must have both the midgard2 PHP extension and the midgard/phpcr package installed. The configuration is similar, except for the session backend, which should be something like:

    # configure the PHPCR session
            type: midgard2
            db_type: SQLite
            db_name: cmf
            db_dir: /tmp
            db_init: true
            blobdir: /tmp/cmf-blobs

The settings here correspond to Midgard2 repository parameters as explained in the getting started document.


You can access the PHPCR services like this:


namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
    public function indexAction()
        // PHPCR session instance
        $session = $this->container->get('doctrine_phpcr.default_session');
        // PHPCR ODM document manager instance
        $documentManager = $this->container->get('doctrine_phpcr.odm.default_document_manager');


You can tag services to listen to Doctrine phpcr events. It works the same way as for Doctrine ORM. The only differences are

  • use the tag name doctrine_phpcr.event_listener resp. doctrine_phpcr.event_subscriber instead of doctrine.event_listener.
  • expect the argument to be of class Doctrine\ODM\PHPCR\Event\LifecycleEventArgs rather than in the ORM namespace.

You can register for the events as described in the PHPCR-ODM documentation.

        class: Acme\SearchBundle\Listener\SearchIndexer
                - { name: doctrine_phpcr.event_listener, event: postPersist }

More information on the doctrine event system integration is in this symfony cookbook entry.

Additional requirements for the doctrine:phpcr:fixtures:load command

To use the doctrine:phpcr:fixtures:load command, you additionally need the Doctrine data-fixtures and the symfony doctrine fixtures bundle:


The bundle provides a couple of symfony commands. To execute them, from your main project folder run

app/console.php <command> [options] [arguments]

Look for the commands that start with doctrine:phpcr.


The fixtures classes must implement Doctrine\Common\DataFixtures\FixtureInterface.

Here is an example of fixture:


namespace MyBundle\DataFixtures\PHPCR;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\FixtureInterface;

class LoadMyData implements FixtureInterface
    public function load(ObjectManager $manager)
        // Create and persist your data here...
Jump to Line
Something went wrong with that request. Please try again.