@@ -41,79 +41,100 @@ Creating a new Page
41
41
~~~~~~~~~~~~~~~~~~~
42
42
43
43
To create a page, use the
44
- ``Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page `` object (which
45
- extends from ``Symfony\Cmf\Bundle\SimpleCmsBundle\Model\Page ``)::
44
+ ``Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page `` object::
46
45
47
- use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
48
-
49
- $page = new Page();
50
- $page->setTitle('About Symfony CMF');
51
- $page->setLabel('About');
52
- $page->setBody(...);
46
+ // // src/Acme/MainBundle/DataFixtures/PHPCR/LoadSimpleCms.php
47
+ namespace Acme\DemoBundle\DataFixtures\PHPCR;
53
48
54
- You can also set other things (e.g. tags).
49
+ use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
50
+ use Doctrine\ODM\PHPCR\DocumentManager;
51
+
52
+ class LoadRoutingData implements FixtureInterface
53
+ {
54
+ /**
55
+ * @param DocumentManager $dm
56
+ */
57
+ public function load(ObjectManager $dm)
58
+ {
59
+ $parent = $dm->find(null, '/cms/simple');
60
+ $page = new Page();
61
+ $page->setTitle('About Symfony CMF');
62
+ $page->setLabel('About');
63
+ $page->setBody(...);
64
+
65
+ // the tree position defines the URL
66
+ $page->setPosition($parent, 'about');
67
+
68
+ $dm->persist($page);
69
+ $dm->flush();
70
+ }
71
+ }
72
+
73
+ You can also set other options on the Page (e.g. tags).
55
74
56
75
All pages are stored in a simple tree structure. To set the position, use
57
- ``setPosition ``. The first argument is the name for current page and the
58
- second argument is the parent node . The name of the first argument is used as
59
- the route. For instance, if you have this tree structure:
76
+ ``setPosition ``. The first argument is the parent document, the second the
77
+ name for this page . The names are used for the URL. For instance, you may
78
+ have the following tree structure:
60
79
61
80
.. code-block :: text
62
81
63
82
/cmf/simple/
64
- home/
65
83
about/
66
84
blog/
67
85
symfony-cmf-is-great/
68
86
69
- In this case, you have 4 pages: ``home ``, ``about ``, ``blog `` and
70
- ``symfony-cmf-is-great ``. The page ``symfony-cmf-is-great `` is a child of
71
- ``blog `` and thus has the url ``/blog/symfony-cmf-is-great ``. To create such a
72
- structure, the code looks like this::
87
+ In this case, you have 4 pages: the page at ``/cms/simple ``, ``about ``,
88
+ ``blog `` and ``symfony-cmf-is-great ``. The page at the home has the path
89
+ ``/ ``. The page ``symfony-cmf-is-great `` is a child of ``blog `` and thus
90
+ has the path ``/blog/symfony-cmf-is-great ``. To create such a
91
+ structure, you would do::
73
92
74
- use PHPCR\Util\NodeHelper;
75
- use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
76
-
77
- // the PHPCR-ODM manager, more on that later
78
- $manager = ...;
79
93
80
- $root = NodeHelper::createPath($manager->getPhpcrSession(), '/cmf/simple');
94
+ // // src/Acme/MainBundle/DataFixtures/PHPCR/LoadSimpleCms.php
95
+ namespace Acme\DemoBundle\DataFixtures\PHPCR;
81
96
82
- $home = new Page();
83
- // ... set up home
84
- $home->setPosition($root, 'home');
97
+ use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
98
+ use Doctrine\ODM\PHPCR\DocumentManager;
85
99
86
- $manager->persist($home); // add home to the database
100
+ class LoadRoutingData implements FixtureInterface
101
+ {
102
+ /**
103
+ * @param DocumentManager $dm
104
+ */
105
+ public function load(ObjectManager $dm)
106
+ {
107
+ $root = $dm->find(null, '/cms/simple');
87
108
88
- $about = new Page();
89
- // ... set up about
90
- $about->setPosition($root, 'about');
109
+ $about = new Page();
110
+ // ... set up about
111
+ $about->setPosition($root, 'about');
91
112
92
- $manager ->persist($about); // add about to the database
113
+ $dm ->persist($about);
93
114
94
- $blog = new Page();
95
- // ... set up blog
96
- $blog->setPosition($root, 'blog');
115
+ $blog = new Page();
116
+ // ... set up blog
117
+ $blog->setPosition($root, 'blog');
97
118
98
- $manager ->persist($blog); // add blog to the database
119
+ $dm ->persist($blog);
99
120
100
- $blogPost = new Page();
101
- // ... set up blog post
102
- $blogPost->setPosition($blog, 'symfony-cmf-is-great');
121
+ $blogPost = new Page();
122
+ // ... set up blog post
123
+ $blogPost->setPosition($blog, 'symfony-cmf-is-great');
103
124
104
- $manager ->persist($blogPost); // add blog post to the database
125
+ $dm ->persist($blogPost);
105
126
106
- // as with all doctrine variants, the changes are only saved when the
107
- // flush method is called
108
- $manager->flush();
127
+ $dm->flush();
128
+ }
129
+ }
109
130
110
131
Every PHPCR-ODM document must have a parent document. Parents are never
111
132
created automatically, so we use the PHPCR NodeHelper to ensure we have
112
133
the root element (``/cmf/simple `` in this case).
113
134
114
135
.. note ::
115
136
116
- The ``/cmf/simple `` basepath is actually already created by an
137
+ The Page at ``/cmf/simple `` is created by an
117
138
:ref: `initializer <phpcr-odm-repository-initializers >` of the
118
139
SimpleCmsBundle.
119
140
0 commit comments