From 51118cbd673489ea6efb15da7fbd4a011c23498b Mon Sep 17 00:00:00 2001 From: dantleech Date: Mon, 1 Sep 2014 08:50:26 +0200 Subject: [PATCH] Various fixes for tutorial --- tutorial/content-to-controllers.rst | 6 +- tutorial/make-homepage.rst | 85 +++++++++++++++++++++++++++-- tutorial/the-frontend.rst | 3 +- 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/tutorial/content-to-controllers.rst b/tutorial/content-to-controllers.rst index 53a3ac5d..b0f0554c 100644 --- a/tutorial/content-to-controllers.rst +++ b/tutorial/content-to-controllers.rst @@ -108,7 +108,7 @@ object and all the ``Posts`` to the view:: */ public function pageAction($contentDocument) { - $dm = $this->get('doctrine_phpcr')->getManagerForClass('AcmeBasicCmsBundle:Post'); + $dm = $this->get('doctrine_phpcr')->getManager(); $posts = $dm->getRepository('AcmeBasicCmsBundle:Post')->findAll(); return array( @@ -155,6 +155,10 @@ Add a corresponding Twig template (note that this works because you use the Now have another look at: http://localhost:8000/page/home +.. note:: + + If you get an error, try clearing the cache. + Notice what is happening with the post object and the ``path`` function - you pass the ``Post`` object and the ``path`` function will pass the object to the router and because it implements the ``RouteReferrersReadInterface`` the diff --git a/tutorial/make-homepage.rst b/tutorial/make-homepage.rst index 6dea72b8..a98c9295 100644 --- a/tutorial/make-homepage.rst +++ b/tutorial/make-homepage.rst @@ -103,7 +103,7 @@ node:: public function init(ManagerRegistry $registry) { - $dm = $registry->getManagerForClass('Acme\BasicCmsBundle\Document\Site'); + $dm = $registry->getManager(); if ($dm->find(null, $this->basePath)) { return; } @@ -135,8 +135,8 @@ node:: documents in initializers. With 1.0, you would need to manually set the ``phpcr:class`` property to the right value. -Now modify the existing service configuration for ``GenericInitializer`` as -follows: +Now *remove* the old initializer service (``acme_basiccms.basic_cms.phpcr.initializer``) and +register your new site initializer: .. configuration-block:: @@ -188,8 +188,6 @@ Now empty your repository, reinitialize it and reload your fixtures: .. code-block:: bash - $ php app/console doctrine:phpcr:node:remove /cms - $ php app/console doctrine:phpcr:repository:init $ php app/console doctrine:phpcr:fixtures:load and verify that the ``cms`` node has been created correctly, using the @@ -219,6 +217,83 @@ and verify that the ``cms`` node has been created correctly, using the with the right class. The drawback then is that there are two places where initialization choices take place - do whatever you prefer. +Reconfigure the Admin Tree +-------------------------- + +If you look at your admin interface now, you will notice that the tree has +gone! + +You need to tell the admin tree about the new ``Site`` document which is now +the root of your websites content tree: + +.. configuration-block:: + + .. code-block:: yaml + + sonata_doctrine_phpcr_admin: + # ... + document_tree: + # ... + Acme\BasicCmsBundle\Document\Site: + valid_children: + - all + + .. code-block:: xml + + + + + + + + + + all + + + + + .. code-block:: php + + $container->loadFromExtension('sonata_doctrine_phpcr_admin', array( + // ... + 'document_tree' => array( + 'Acme\BasicCmsBundle\Document\Site' => array( + 'valid_children' => array( + 'all', + ), + ), + // ... + )); + +If you check your admin interface you will see that the ``Site`` document is +now being displayed, however it has no children. You need to map the children on the +``Site`` document, modify it as follows:: + + // src/Acme/BasicCmsBundle/Document/Site.php + + // ... + + /** + * @PHPCR\Document() + */ + class Site + { + /** + * @PHPCR\Children() + */ + protected $children; + + // ... + + public function getChildren() + { + return $this->children; + } + } + +The tree should now again show your website structure. + Create the Make Homepage Button ------------------------------- diff --git a/tutorial/the-frontend.rst b/tutorial/the-frontend.rst index b8fdc087..d63403f3 100644 --- a/tutorial/the-frontend.rst +++ b/tutorial/the-frontend.rst @@ -114,7 +114,8 @@ to which you will add the existing ``Home`` page and an additional ``About`` pag { public function load(ObjectManager $dm) { - // ... + $parent = $dm->find(null, '/cms/pages'); + $rootPage = new Page(); $rootPage->setTitle('main'); $rootPage->setParentDocument($parent);