@@ -77,8 +77,8 @@ dump command:
7777 .. note ::
7878
7979 Previously, the PHPCR tree was compared with a Filesystem. While this
80- gives you a good image of what happens, it's not the truth. You can
81- better compare it to an XML file, where each node is an element and its
80+ gives you a good image of what happens, it's not the only truth. You can
81+ compare it to an XML file, where each node is an element and its
8282 properties are attributes.
8383
8484Doctrine PHPCR-ODM
@@ -90,13 +90,13 @@ directly persisted into and retrieved from the PHPCR tree. This is similar to
9090the Doctrine ORM provided by default in the Symfony Standard Edition, but for
9191PHPCR instead of SQL databases.
9292
93- Creating a Page with code
94- -------------------------
93+ Creating Content from Code
94+ --------------------------
9595
96- Now you know a little bit more about PHPCR and you know the tool to interact
96+ Now that you know a little bit more about PHPCR and you know the tool to interact
9797with it, you can start using it yourself. In the previous chapter, you edited
98- a page by using a yaml file which was parsed by the fixture loader of the
99- sandbox. This time, you'll create a page by doing it yourself .
98+ a page by using a Yaml file which was parsed by the fixture loader of the
99+ sandbox. This time, you'll create a page with PHP code .
100100
101101First, you have to create a new DataFixture to add your new page. You do this
102102by creating a new class in the AppBundle::
@@ -108,7 +108,7 @@ by creating a new class in the AppBundle::
108108 use Doctrine\Common\DataFixtures\FixtureInterface;
109109 use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
110110
111- class LoadPageData implements FixtureInterface, OrderedFixtureInterface
111+ class LoadQuickTourData implements FixtureInterface, OrderedFixtureInterface
112112 {
113113 public function getOrder()
114114 {
@@ -119,91 +119,56 @@ by creating a new class in the AppBundle::
119119
120120 public function load(ObjectManager $documentManager)
121121 {
122+ // you will add code to this method in the next steps
122123 }
123124 }
124125
125126The ``$documentManager `` is the object which will persist the document to
126127PHPCR. But first, you have to create a new Page document::
127128
128129 use Doctrine\ODM\PHPCR\DocumentManager;
129- use Symfony\Cmf\Bundle\SimpleCmsBundle \Doctrine\Phpcr\Page ;
130+ use Symfony\Cmf\Bundle\ContentBundle \Doctrine\Phpcr\StaticContent ;
130131
131132 // ...
132133 public function load(ObjectManager $documentManager)
133134 {
134135 if (!$documentManager instanceof DocumentManager) {
135- $class = get_class($documentManager);
136- throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
136+ throw new \RuntimeException(sprintf(
137+ 'Fixture requires a PHPCR ODM DocumentManager instance, instance of "%s" given.',
138+ get_class($documentManager)
139+ ));
137140 }
138141
139- $page = new Page(); // create a new Page object (document)
140- $page->setName('quick-tour'); // the name of the node
141-
142- vno sandbox übernehmen
143-
144- $page->setLabel('Another new Page');
145- $page->setTitle('Another new Page');
146- $page->setBody('I have added this page myself!');
142+ $content = new StaticContent();
143+ $content->setName('quick-tour'); // the name of the node
144+ $content->setTitle('Quick tour new Page');
145+ $content->setBody('I have added this page myself!');
147146 }
148147
149- Each document needs a parent. In this case, the parent should just be the root
148+ Each document needs a parent. In this case, the parent should be the content root
150149node. To do this, we first retrieve the root document from PHPCR and then set
151150it as its parent::
152151
153152 public function load(ObjectManager $documentManager)
154153 {
155154 // ...
156- // get root document (/cms/simple)
157- $simpleCmsRoot = $documentManager->find(null, '/cms/simple');
158-
159- $page->setParentDocument($simpleCmsRoot); // set the parent to the root
155+ // get the root document
156+ $contentRoot = $documentManager->find(null, '/cms/content');
157+ $content->setParentDocument($contentRoot); // set the parent to the root
160158 }
161159
162- And at last , we have to tell the Document Manager to persist our Page
160+ And finally , we have to tell the Document Manager to persist our content
163161document using the Doctrine API::
164162
165163 public function load(ObjectManager $documentManager)
166164 {
167165 // ...
168- $documentManager->persist($page ); // add the Page in the queue
169- $documentManager->flush(); // add the Page to PHPCR
166+ $documentManager->persist($content ); // tell the document manager to track the content
167+ $documentManager->flush(); // doctrine is like a toilet: never forget to flush
170168 }
171169
172170Now you need to execute the ``doctrine:phpcr:fixtures:load `` command again.
173- When dumping the nodes again, your new page should turn up under /cms/content.
174-
175- To actually see this page in the browser, we need a route::
176-
177- public function load(ObjectManager $documentManager)
178- {
179- // ...
180- $route = new Route();
181- $routeRoot = $documentManager->find(null, '/cms/routes/en');
182- $route->setPosition($routeRoot, 'quick-tour');
183- $route->setContent($page);
184- $documentManager->persist($route);
185- }
186-
187- And we add a menu entry to link to this page, and flush the document manager
188- at the end::
189-
190- public function load(ObjectManager $documentManager)
191- {
192- $menu = new MenuNode();
193- $menu->setName('new_page');
194- $menu->setLabel('Quick Tour');
195- $menu->setContent($page);
196- $menuMain = $documentManager->find(null, '/cms/menu/main');
197- $menu->setParentDocument($menuMain);
198- $documentManager->persist($menu);
199-
200- $documentManager->flush();
201- }
202-
203- Re-run the fixtures loading command and then refresh the web site. Your new
204- page will be added, with a menu entry at the bottom of the menu!
205-
206- .. image :: ../_images/quick_tour/the-model-new-page.png
171+ When dumping the nodes again, your new page should show up under ``/cms/content/quick-tour ``!
207172
208173.. seealso ::
209174
0 commit comments