@@ -4,8 +4,8 @@ Part 1 - Getting Started
4
4
Initializing the Project
5
5
~~~~~~~~~~~~~~~~~~~~~~~~
6
6
7
- First, follow the generic steps in :doc: `create_new_project_phpcr_odm ` to create a new project using
8
- the PHPCR-ODM.
7
+ First, follow the generic steps in :doc: `create_new_project_phpcr_odm ` to
8
+ create a new project using the PHPCR-ODM.
9
9
10
10
Install Additional Bundles
11
11
..........................
@@ -25,7 +25,7 @@ Update ``composer.json`` to require them:
25
25
...
26
26
require: {
27
27
...
28
- " symfony-cmf/routing-auto-bundle" : " dev-master " ,
28
+ " symfony-cmf/routing-auto-bundle" : " 1.0.0@alpha " ,
29
29
" symfony-cmf/menu-bundle" : " 1.0" ,
30
30
" sonata-project/doctrine-phpcr-admin-bundle" : " dev-master" ,
31
31
" doctrine/data-fixtures" : " 1.0.0"
@@ -62,7 +62,7 @@ database:
62
62
$ mysqladmin create symfony -u root
63
63
64
64
This will create a new database called ``symfony `` - this is the name used by
65
- default in the Symfony Standard Edition, change as might be necessary.
65
+ default in the Symfony Standard Edition, change it as might be necessary.
66
66
67
67
The Doctrine DBAL backend needs to be initialized, the following command
68
68
will create the MySQL schema required to store the hierarchical
@@ -78,6 +78,9 @@ node content of the PHPCR content repository:
78
78
backend and does not require such initialization. It does however require
79
79
the use of Java.
80
80
81
+ Generate the Bundle
82
+ ...................
83
+
81
84
Now you can generate the bundle in which you will write most of your code:
82
85
83
86
.. code-block :: bash
@@ -169,7 +172,7 @@ to reduce code duplication::
169
172
170
173
Traits are only available as of PHP 5.4. If you are running a lesser
171
174
version of PHP you may copy the above code into each class to have the
172
- same effect. You may not, however, ``extend `` one class from another , as
175
+ same effect. You may not, however, ``extend `` one class from the other , as
173
176
this will cause unintended behavior in the admin integration later on.
174
177
175
178
The ``Page `` class is therefore nice and simple::
@@ -188,11 +191,10 @@ The ``Page`` class is therefore nice and simple::
188
191
use ContentTrait;
189
192
}
190
193
191
- Note that the page documet should be ``referenceable ``. This will enable
194
+ Note that the page document should be ``referenceable ``. This will enable
192
195
other documents to hold a reference to the page. The ``Post `` class will also
193
- be referenceable and in addition the ``Post `` class will automatically set the
194
- date if it has not been explicitly set using the `pre persist lifecycle
195
- event `_::
196
+ be referenceable and in addition will automatically set the date using the
197
+ `pre persist lifecycle event `_ if it has not been explicitly set previously::
196
198
197
199
// src/Acme/BasicCms/Document/Post.php
198
200
namespace Acme\BasicCmsBundle\Document;
@@ -227,21 +229,21 @@ event`_::
227
229
return $this->date;
228
230
}
229
231
230
- public function setDate($date)
232
+ public function setDate(\DateTime $date)
231
233
{
232
234
$this->date = $date;
233
235
}
234
236
}
235
237
236
238
Both the ``Post `` and ``Page `` classes implement the
237
- ``RouteReferrersReadInterface `` which enables the
238
- `DynamicRouter to generate URLs `_. (for example with `` {{ path(content) }} ``
239
- in Twig).
239
+ ``RouteReferrersReadInterface ``. This interface enables the
240
+ `DynamicRouter to generate URLs `_ from instances of these classes. (for
241
+ example with `` {{ path(content) }} `` in Twig).
240
242
241
243
Repository Initializer
242
244
~~~~~~~~~~~~~~~~~~~~~~
243
245
244
- `Repository initializers `_ enable you to establish and maintain PHPCR nodes
246
+ :ref: `Repository initializers < ../../bundles/phpcr_odm >` enable you to establish and maintain PHPCR nodes
245
247
required by your application, for example you will need the paths
246
248
``/cms/pages ``, ``/cms/posts `` and ``/cms/routes ``. The ``GenericInitializer ``
247
249
class can be used easily initialize a list of paths. Add the following to your
@@ -255,7 +257,8 @@ service container configuration:
255
257
services :
256
258
acme.basic_cms.phpcr.initializer :
257
259
class : Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer
258
- arguments : [ "/cms/pages", "/cms/posts", "/cms/routes" ]
260
+ arguments :
261
+ - ["/cms/pages", "/cms/posts", "/cms/routes"]
259
262
tags :
260
263
- { name: doctrine_phpcr.initializer }
261
264
@@ -313,8 +316,10 @@ reinitialize) the repository:
313
316
314
317
.. note ::
315
318
316
- This command is an `idempotent `_, which means that it should be safe to run
317
- it multiple times, even when you have data in your repository.
319
+ This command is `idempotent `_, which means that it is safe to run
320
+ it multiple times, even when you have data in your repository. Note
321
+ however that it is the responsibility of the initializer to respect
322
+ idempotency!
318
323
319
324
Create Data Fixtures
320
325
~~~~~~~~~~~~~~~~~~~~
@@ -324,20 +329,19 @@ Create a page for your CMS::
324
329
// src/Acme/BasicCmsBundle/DataFixtures/PHPCR/LoadPageData.php
325
330
namespace Acme\BasicCmsBundle\DataFixtures\PHPCR;
326
331
332
+ use Acme\BasicCmsBundle\Document\Page;
327
333
use Doctrine\Common\DataFixtures\FixtureInterface;
328
334
use Doctrine\Common\Persistence\ObjectManager;
329
- use Acme\BasicCmsBundle\Document\Page;
330
- use PHPCR\Util\NodeHelper;
335
+ use PHPCR\Util\NodeHelpen;
331
336
332
337
class LoadPageData implements FixtureInterface
333
338
{
334
339
public function load(ObjectManager $dm)
335
340
{
336
- NodeHelper::createPath($dm->getPhpcrSession(), '/cms/pages');
337
341
$parent = $dm->find(null, '/cms/pages');
338
342
339
343
$page = new Page();
340
- $page->setTitle('Home');
344
+ $page->setTitle
341
345
$page->setParent($parent);
342
346
$page->setContent(<<<HERE
343
347
Welcome to the homepage of this really basic CMS.
@@ -363,7 +367,6 @@ and add some posts::
363
367
{
364
368
public function load(ObjectManager $dm)
365
369
{
366
- NodeHelper::createPath($dm->getPhpcrSession(), '/cms/posts');
367
370
$parent = $dm->find(null, '/cms/posts');
368
371
369
372
foreach (array('First', 'Second', 'Third', 'Forth') as $title) {
@@ -390,16 +393,6 @@ and load the fixtures:
390
393
391
394
You should now have some data in your content repository.
392
395
393
- .. note ::
394
-
395
- The classes above use ``NodeHelper::createPath `` to create the paths
396
- ``/cms/posts `` and ``/cms/pages `` - this is exactly what the
397
- initializer did -- why do the classes do it again? This is a known issue - the
398
- data fixtures loader will purge the workspace and it will **not ** call the
399
- initializer, so when using data fixtures it is currently necessary to manually
400
- create the paths.
401
-
402
-
403
396
.. _`routingautobundle documentation` : http://symfony.com/doc/current/cmf/bundles/routing_auto.html
404
397
.. _`dynamicrouter to generate urls` : http://symfony.com/doc/current/cmf/bundles/routing/dynamic.html#url-generation-with-the-dynamicrouterA
405
398
.. _`idempotent` : http://en.wiktionary.org/wiki/idempotent
0 commit comments