I`m following the tutorial Creating a Basic CMS and i got stuck when triying to create a custom initializer for my site document class, the documentation in the symfonycmf cook book page is using doctrine/phpcr-bundle 1.0 and i'm using dev-master 1.1-dev, the reason i'm using dev-master version is because with that configuration my dependencies work fine
-
And what's your question/problem? – Wouter J Apr 12 '14 at 17:32
-
i apoligize my question is the title of my question How to create a custom PHPCRBundle initializer in doctrine/phpcr-bundle “dev-master”: “1.1-dev” because there is no documentation about it if you see the github repository there you can notice that the generic initializer from version 1.0 is quite diference from the current master version, see the link in my question thats the documentation for version 1.0 see that my depencies work only in dev-master so thats the reason i need docs for the current master version – metalvarez Apr 12 '14 at 23:55
1 Answers
After carefully checking the two versions i realize that after all the differences between the two versions where not so big, in the 1.0 version the Doctrine\Bundle\PHPCRBundle\Initializer\InitializerInterface is injected with an PCR\SessionInterface object in his init method, that session object its like the entity manager for doctrine orm i think, as it performs the save method to presist in the odm, but in the current master version the interface inject a Doctrine\Bundle\PHPCRBundle\ManagerRegistry and with this object you can get the connection session with the method $session = $registry->getConnection(); here is the code example.
class SiteInitializer implements InitializerInterface {
public function init(ManagerRegistry $registry) {
$session = $registry->getConnection();
NodeHelper::createPath($session, '/cms/pages');
NodeHelper::createPath($session, '/cms/posts');
NodeHelper::createPath($session, '/cms/routes');
$session->save();
$cms = $session->getNode('/cms');
$cms->setProperty(
'phpcr:class', 'Acme\BasicCmsBundle\Document\Site'
);
$session->save();
}
}
@dbu thanks to you and your tean for this great work in the symfony cmf, i hope you can check this question and if you find any errors or mistakes please correct us if we are doing something wrong.

- 606
- 1
- 8
- 14
-
while this works, the point of injecting the registry rather than phpcr session was to allow to use the document manager to create documents directly. see for example https://github.com/symfony-cmf/SimpleCmsBundle/blob/master/Initializer/HomepageInitializer.php#L38-L54 – dbu Apr 14 '14 at 07:47
-
btw, if you could do a PR on the symfony-cmf-docs repository, that would be highly appreciated. – dbu Apr 14 '14 at 07:48
-
the doc was not very clean, did a PR to improve the situation: https://github.com/symfony-cmf/symfony-cmf-docs/pull/446 – dbu Apr 14 '14 at 10:03