@@ -77,8 +77,8 @@ dump command:
77
77
.. note::
78
78
79
79
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
82
82
properties are attributes.
83
83
84
84
Doctrine PHPCR-ODM
@@ -90,13 +90,13 @@ directly persisted into and retrieved from the PHPCR tree. This is similar to
90
90
the Doctrine ORM provided by default in the Symfony Standard Edition, but for
91
91
PHPCR instead of SQL databases.
92
92
93
- Creating a Page with code
94
- -------------------------
93
+ Creating Content from Code
94
+ --------------------------
95
95
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
97
97
with 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 .
100
100
101
101
First, you have to create a new DataFixture to add your new page. You do this
102
102
by creating a new class in the AppBundle::
@@ -108,7 +108,7 @@ by creating a new class in the AppBundle::
108
108
use Doctrine\Common\DataFixtures\FixtureInterface;
109
109
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
110
110
111
- class LoadPageData implements FixtureInterface, OrderedFixtureInterface
111
+ class LoadQuickTourData implements FixtureInterface, OrderedFixtureInterface
112
112
{
113
113
public function getOrder()
114
114
{
@@ -119,91 +119,56 @@ by creating a new class in the AppBundle::
119
119
120
120
public function load(ObjectManager $documentManager)
121
121
{
122
+ // you will add code to this method in the next steps
122
123
}
123
124
}
124
125
125
126
The ``$documentManager`` is the object which will persist the document to
126
127
PHPCR. But first, you have to create a new Page document::
127
128
128
129
use Doctrine\ODM\PHPCR\DocumentManager;
129
- use Symfony\Cmf\Bundle\SimpleCmsBundle \Doctrine\Phpcr\Page ;
130
+ use Symfony\Cmf\Bundle\ContentBundle \Doctrine\Phpcr\StaticContent ;
130
131
131
132
// ...
132
133
public function load(ObjectManager $documentManager)
133
134
{
134
135
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
+ ));
137
140
}
138
141
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!');
147
146
}
148
147
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
150
149
node. To do this, we first retrieve the root document from PHPCR and then set
151
150
it as its parent::
152
151
153
152
public function load(ObjectManager $documentManager)
154
153
{
155
154
// ...
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
160
158
}
161
159
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
163
161
document using the Doctrine API::
164
162
165
163
public function load(ObjectManager $documentManager)
166
164
{
167
165
// ...
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
170
168
}
171
169
172
170
Now 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``!
207
172
208
173
.. seealso::
209
174
0 commit comments