Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit b7336e9

Browse files
committed
Updated
1 parent 524c2d3 commit b7336e9

File tree

7 files changed

+78
-64
lines changed

7 files changed

+78
-64
lines changed

cookbook/creating_a_cms/005-introduction.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
single: Tutorial, Creating a CMS, RoutingAuto, PHPCR-ODM
33
single: MenuBundle, SonataAdmin, SonataDoctrineAdminBundle
44

5-
Creating a Basic CMS Using the RoutingAutoBundle
5+
Creating a Basic CMS using the RoutingAutoBundle
66
================================================
77

8-
This three part article will show you how to create a basic CMS from scratch
8+
This series of articles will show you how to create a basic CMS from scratch
99
using the following bundles:
1010

11-
* :doc:`../bundles/routing_auto`;
12-
* :doc:`../bundles/phpcr_odm`;
13-
* :doc:`../bundles/menu/index`;
11+
* :doc:`../../bundles/routing_auto`;
12+
* :doc:`../../bundles/phpcr_odm`;
13+
* :doc:`../../bundles/menu/index`;
1414
* `SonataDoctrinePhpcrAdminBundle`_.
1515

1616
It is assumed that you have:

cookbook/creating_a_cms/010-getting-started.rst

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Part 1 - Getting Started
44
Initializing the Project
55
~~~~~~~~~~~~~~~~~~~~~~~~
66

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.
99

1010
Install Additional Bundles
1111
..........................
@@ -25,7 +25,7 @@ Update ``composer.json`` to require them:
2525
...
2626
require: {
2727
...
28-
"symfony-cmf/routing-auto-bundle": "dev-master",
28+
"symfony-cmf/routing-auto-bundle": "1.0.0@alpha",
2929
"symfony-cmf/menu-bundle": "1.0",
3030
"sonata-project/doctrine-phpcr-admin-bundle": "dev-master",
3131
"doctrine/data-fixtures": "1.0.0"
@@ -62,7 +62,7 @@ database:
6262
$ mysqladmin create symfony -u root
6363
6464
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.
6666

6767
The Doctrine DBAL backend needs to be initialized, the following command
6868
will create the MySQL schema required to store the hierarchical
@@ -78,6 +78,9 @@ node content of the PHPCR content repository:
7878
backend and does not require such initialization. It does however require
7979
the use of Java.
8080

81+
Generate the Bundle
82+
...................
83+
8184
Now you can generate the bundle in which you will write most of your code:
8285

8386
.. code-block:: bash
@@ -169,7 +172,7 @@ to reduce code duplication::
169172

170173
Traits are only available as of PHP 5.4. If you are running a lesser
171174
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
173176
this will cause unintended behavior in the admin integration later on.
174177

175178
The ``Page`` class is therefore nice and simple::
@@ -188,11 +191,10 @@ The ``Page`` class is therefore nice and simple::
188191
use ContentTrait;
189192
}
190193

191-
Note that the page documet should be ``referenceable``. This will enable
194+
Note that the page document should be ``referenceable``. This will enable
192195
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::
196198

197199
// src/Acme/BasicCms/Document/Post.php
198200
namespace Acme\BasicCmsBundle\Document;
@@ -227,21 +229,21 @@ event`_::
227229
return $this->date;
228230
}
229231

230-
public function setDate($date)
232+
public function setDate(\DateTime $date)
231233
{
232234
$this->date = $date;
233235
}
234236
}
235237

236238
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).
240242

241243
Repository Initializer
242244
~~~~~~~~~~~~~~~~~~~~~~
243245

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
245247
required by your application, for example you will need the paths
246248
``/cms/pages``, ``/cms/posts`` and ``/cms/routes``. The ``GenericInitializer``
247249
class can be used easily initialize a list of paths. Add the following to your
@@ -255,7 +257,8 @@ service container configuration:
255257
services:
256258
acme.basic_cms.phpcr.initializer:
257259
class: Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer
258-
arguments: [ "/cms/pages", "/cms/posts", "/cms/routes" ]
260+
arguments:
261+
- ["/cms/pages", "/cms/posts", "/cms/routes"]
259262
tags:
260263
- { name: doctrine_phpcr.initializer }
261264
@@ -313,8 +316,10 @@ reinitialize) the repository:
313316
314317
.. note::
315318

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!
318323

319324
Create Data Fixtures
320325
~~~~~~~~~~~~~~~~~~~~
@@ -324,20 +329,19 @@ Create a page for your CMS::
324329
// src/Acme/BasicCmsBundle/DataFixtures/PHPCR/LoadPageData.php
325330
namespace Acme\BasicCmsBundle\DataFixtures\PHPCR;
326331

332+
use Acme\BasicCmsBundle\Document\Page;
327333
use Doctrine\Common\DataFixtures\FixtureInterface;
328334
use Doctrine\Common\Persistence\ObjectManager;
329-
use Acme\BasicCmsBundle\Document\Page;
330-
use PHPCR\Util\NodeHelper;
335+
use PHPCR\Util\NodeHelpen;
331336

332337
class LoadPageData implements FixtureInterface
333338
{
334339
public function load(ObjectManager $dm)
335340
{
336-
NodeHelper::createPath($dm->getPhpcrSession(), '/cms/pages');
337341
$parent = $dm->find(null, '/cms/pages');
338342

339343
$page = new Page();
340-
$page->setTitle('Home');
344+
$page->setTitle
341345
$page->setParent($parent);
342346
$page->setContent(<<<HERE
343347
Welcome to the homepage of this really basic CMS.
@@ -363,7 +367,6 @@ and add some posts::
363367
{
364368
public function load(ObjectManager $dm)
365369
{
366-
NodeHelper::createPath($dm->getPhpcrSession(), '/cms/posts');
367370
$parent = $dm->find(null, '/cms/posts');
368371

369372
foreach (array('First', 'Second', 'Third', 'Forth') as $title) {
@@ -390,16 +393,6 @@ and load the fixtures:
390393
391394
You should now have some data in your content repository.
392395

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-
403396
.. _`routingautobundle documentation`: http://symfony.com/doc/current/cmf/bundles/routing_auto.html
404397
.. _`dynamicrouter to generate urls`: http://symfony.com/doc/current/cmf/bundles/routing/dynamic.html#url-generation-with-the-dynamicrouterA
405398
.. _`idempotent`: http://en.wiktionary.org/wiki/idempotent

cookbook/creating_a_cms/020-auto-routing.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ Part 2: Automatic Routing
22
-------------------------
33

44
The routes (URLs) to your content will be automatically created and updated
5-
using the RoutingAutoBundle. This bundle is powerful and somewhat complicated.
6-
For a full a full explanation refer to the `RoutingAutoBundle documentation`_.
5+
using the RoutingAutoBundle. This bundle uses a configuration language to
6+
specify automatic creation of routes, which can be a bit hard to grasp the
7+
first time you see it.
8+
9+
For a full a full explanation refer to the
10+
:doc:`../../bundles/routing_auto.rst`_.
711

812
In summary, you will configure the auto routing system to create a new auto
913
routing document in the routing tree for every post or content created. The
@@ -19,13 +23,12 @@ the contents will be avilable at the following URLs:
1923
* **About**: ``http://localhost:8000/page/about``
2024
* etc.
2125

22-
2326
Enable the Dynamic Router
2427
~~~~~~~~~~~~~~~~~~~~~~~~~
2528

26-
The RoutingAutoBundle uses the CMFs `RoutingBundle`_ which enables routes to
27-
be provided from a database (as opposed to being provided from
28-
``routing.[yml|xml|php]`` files for example).
29+
The RoutingAutoBundle uses the CMF `RoutingBundle`_ which enables routes to
30+
be provided from a database (in addition to being provided from
31+
the routing configuration files as in core Symfony 2).
2932

3033
Add the following to your application configuration:
3134

@@ -78,12 +81,12 @@ Add the following to your application configuration:
7881
7982
This will:
8083

81-
#. Cause the default Symfony router to be replaced by the chain router. The
84+
#. Cause the default Symfony router to be replaced by the chain router. The
8285
chain router enables you to have multiple routers in your application. You
8386
add the dynamic router (which can retrieve routes from the database) and
8487
the default Symfony router (which retrieves routes from configuration
85-
files). The number indicates the order of precedence - the router with the
86-
lowest number will be called first.;
88+
files). The number indicates the order of precedence - the router with the
89+
lowest number will be called first;
8790
#. Configure the **dynamic** router which you have added to the router chain.
8891
You specify that it should use the PHPCR backend and that the *root* route
8992
can be found at ``/cms/routes``.
@@ -177,7 +180,7 @@ Now you will need to include this configuration:
177180
.. code-block:: xml
178181
179182
<!-- src/Acme/BasicCmsBUndle/Resources/config/config.yml -->
180-
?xml version="1.0" encoding="UTF-8" ?>
183+
<?xml version="1.0" encoding="UTF-8" ?>
181184
<container
182185
xmlns="http://symfony.com/schema/dic/services"
183186
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

cookbook/creating_a_cms/030-sonata-admin.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Part 3 - The Backend
22
--------------------
33

4-
The `SonataAdminBundle`_ bundle will provide our administration interface.
4+
In this chapter you will build an administration interface with the help
5+
of the `SonataAdminBundle`_.
56

67
Configure Sonata
78
~~~~~~~~~~~~~~~~
@@ -33,13 +34,14 @@ Sonata requires the ``sonata_block`` bundle to be configured in your main config
3334
.. code-block:: yaml
3435
3536
# app/config/config.yml
37+
3638
# ...
3739
sonata_block:
3840
default_contexts: [cms]
3941
blocks:
4042
# Enable the SonataAdminBundle block
4143
sonata.admin.block.admin_list:
42-
contexts: [admin]
44+
contexts: [admin]
4345
4446
.. code-block:: xml
4547
@@ -74,6 +76,7 @@ and it requires the following entries in your routing file:
7476
.. code-block:: yaml
7577
7678
# app/config/routing.yml
79+
7780
admin:
7881
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
7982
prefix: /admin
@@ -137,6 +140,8 @@ No translations? Uncomment the translator in the configuration file:
137140

138141
.. code-block:: yaml
139142
143+
# app/config/config.yml
144+
140145
# ...
141146
framework:
142147
# ...
@@ -217,7 +222,7 @@ the RoutingBundle admin as follows:
217222
),
218223
));
219224
220-
.. note::
225+
.. tip::
221226

222227
All Sonata Admin aware CMF bundles have such a configuration option and it
223228
prevents the admin class (or classes) from being registered.
@@ -295,6 +300,12 @@ to avoid code duplication::
295300
}
296301
}
297302

303+
.. note::
304+
305+
In the ``prePersist`` method of the ``PageAdmin`` you specify always a
306+
fixed path, in the future you may want to modify this behavior to
307+
enable pages to be structured (for example to have nested menus).
308+
298309
Now you just need to register these classes in the dependency injection
299310
container configuration:
300311

cookbook/creating_a_cms/040-the-frontend.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ You can map a default controller for all instances of ``Page``:
5757
This will cause requests to be forwarded to this controller when the route
5858
which matches the incoming request is provided by the dynamic router **and**
5959
the content document that that route references is of class
60-
``Acme\BasicCmsBundle\Document\Page``
60+
``Acme\BasicCmsBundle\Document\Page``.
6161

6262
Now create the action in the default controller - you can pass the ``Page``
6363
object and all the ``Posts`` to the view::
6464

6565
// src/Acme/BasicCmsBundle/Controller/DefaultController.php
66-
//..
66+
67+
// ...
6768
class DefaultController extends Controller
6869
{
6970
// ...
@@ -77,7 +78,7 @@ object and all the ``Posts`` to the view::
7778
$posts = $dm->getRepository('Acme\BasicCmsBundle\Document\Post')->findAll();
7879

7980
return array(
80-
'page' => $contentDocument,
81+
'page' => $contentDocument,
8182
'posts' => $posts,
8283
);
8384
}
@@ -106,7 +107,7 @@ Add a corresponding twig template (note that this works because you use the
106107

107108
<!-- src/Acme/BasicCmsBundle/Resources/views/Default/page.html.twig -->
108109
<h1><?php echo $page->getTitle() ?></h1>
109-
<p><?php echo $page->content ?></p>
110+
<p><?php echo $page->getContent() ?></p>
110111
<h2>Our Blog Posts</h2>
111112
<ul>
112113
<?php foreach($posts as $post) : ?>
@@ -172,16 +173,16 @@ KnpMenuBundle::
172173
'label' => $this->title,
173174
'content' => $this,
174175

175-
'attributes' => array(),
176+
'attributes' => array(),
176177
'childrenAttributes' => array(),
177-
'displayChildren' => true,
178-
'linkAttributes' => array(),
179-
'labelAttributes' => array(),
178+
'displayChildren' => true,
179+
'linkAttributes' => array(),
180+
'labelAttributes' => array(),
180181
);
181182
}
182183
}
183184

184-
.. note::
185+
.. caution::
185186

186187
Don't forget to add the ``Knp\Menu\NodeInterface`` use statement!
187188

@@ -267,7 +268,7 @@ applications kernel::
267268
}
268269
}
269270

270-
Now you can register the PhpcrMenuProvider from the menu bundle in the service container
271+
Now you can register the ``PhpcrMenuProvider`` from the menu bundle in the service container
271272
configuration:
272273

273274
.. configuration-block::
@@ -370,6 +371,7 @@ and finally lets render the menu!
370371

371372
<!-- src/Acme/BasicCmsBundle/Resources/views/Default/page.html.php -->
372373

374+
<!-- ... -->
373375
<?php echo $view['knp_menu']->render('main') ?>
374376

375377
Note that ``main`` refers to the name of the root page you added in the data

0 commit comments

Comments
 (0)