Skip to content
Newer
Older
100644 359 lines (252 sloc) 11.3 KB
8f43821 @lsmith77 lots of details, added SonataDoctrinePhpcrAdminBundle
lsmith77 authored Oct 27, 2012
1 Installing and configuring Doctrine PHPCR-ODM
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
2 =============================================
3
1f9e667 Changes following pull request comments.
Lars Janssen authored Nov 14, 2012
4 The Symfony2 CMF needs somewhere to store the content. Many of the bundles provide documents and
5 mappings for the PHP Content Repository - Object Document Mapper (PHPCR-ODM), and the documentation
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
6 is currently based around using this. However, it should also be possible to use any other form of
1f9e667 Changes following pull request comments.
Lars Janssen authored Nov 14, 2012
7 content storage, such as another ORM/ODM or MongoDB.
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
8
9 The goal of this tutorial is to install and configure Doctrine PHPCR-ODM, ready for you to get
10 started with the CMF.
11
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
12 For more details see the `full PHPCR-ODM documentation <http://www.doctrine-project.org/projects/phpcr-odm.html>`_.
13 Some additional information can be found in the :doc:`../bundles/phpcr-odm` reference,
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
14 which for the most part mimics the standard `DoctrineBundle <https://github.com/doctrine/DoctrineBundle>`_.
15
16 Finally for information about PHPCR see the `official PHPCR website <http://phpcr.github.com>`_.
17
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
18 .. tip::
19
20 If you just want to use PHPCR but not the PHPCR-ODM, you can skip the step about registering
21 annotations and the part of the configuration section starting with `odm`.
22
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
23 .. index:: PHPCR, ODM
24
25 Preconditions
26 -------------
27 - php >= 5.3
28 - libxml version >= 2.7.0 (due to a bug in libxml http://bugs.php.net/bug.php?id=36501)
29 - phpunit >= 3.6 (if you want to run the tests)
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
30 - Symfony2 (version 2.1.x)
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
31
32 Installation
33 ------------
34
35 Choosing a content repository
36 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 The first thing to decide is what content repository to use. A content repository is essentially
38 a database that will be responsible for storing all the content you want to persist. It provides
f5c0bc7 fixed typos
Eriksen Costa authored Nov 4, 2012
39 an API that is optimized for the needs of a CMS (tree structures, references, versioning, full
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
40 text search etc.). While every content repository can have very different requirements and
41 performance characteristics, the API is the same for all of them.
42
9e6c7f3 @greg0ire punctuation
greg0ire authored Nov 22, 2012
43 Furthermore, since the API defines an export/import format, you can always switch to a different
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
44 content repository implementation later on.
45
46 These are the available choices:
47
1028f2d Small fixes to a couple of tutorials.
Lars Janssen authored Nov 11, 2012
48 * **Jackalope with Jackrabbit** (Jackrabbit requires Java, it can persist into the file system, a database etc.)
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
49 * **Jackalope with Doctrine DBAL** (requires an RDBMS like MySQL, PostgreSQL or SQLite)
50 * **Midgard** (requires the midgard2 PHP extension and an RDBMS like MySQL, PostgreSQL or SQLite)
51
52 The following documentation includes examples for all of the above options.
53
54 .. tip::
55
56 If you are just getting started with the CMF, it is best to choose a content repository based
57 on a storage engine that you are already familiar with. For example,
58 **Jackalope with Doctrine DBAL** will work with your existing RDBMS and does not require you
fbece45 Small tweaks to the PHPCR install doc
Lars Janssen authored Nov 13, 2012
59 to install Java or the midgard2 PHP extension. Once you have a working application it should be
60 easy to switch to another option.
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
61
62
63 Download the bundles
64 ~~~~~~~~~~~~~~~~~~~~
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
65 Add the following to your ``composer.json`` file, depending on your chosen content repository.
66
67 | **Jackalope with Jackrabbit**
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
68
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 16, 2012
69 .. code-block:: javascript
70
cad8dc4 @lsmith77 added stability dev
lsmith77 authored Dec 6, 2012
71 "minimum-stability": "dev",
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
72 "require": {
73 ...
f4e170b @matteosister Update tutorials/installing-configuring-doctrine-phpcr-odm.rst
matteosister authored Oct 28, 2012
74 "jackalope/jackalope-jackrabbit": "1.0.*",
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
75 "doctrine/phpcr-bundle": "1.0.*",
f4e170b @matteosister Update tutorials/installing-configuring-doctrine-phpcr-odm.rst
matteosister authored Oct 28, 2012
76 "doctrine/phpcr-odm": "1.0.*"
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
77 }
78
1f9e667 Changes following pull request comments.
Lars Janssen authored Nov 14, 2012
79 | **Jackalope with Doctrine DBAL**
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
80
1f9e667 Changes following pull request comments.
Lars Janssen authored Nov 14, 2012
81 .. code-block:: javascript
82
cad8dc4 @lsmith77 added stability dev
lsmith77 authored Dec 6, 2012
83 "minimum-stability": "dev",
1f9e667 Changes following pull request comments.
Lars Janssen authored Nov 14, 2012
84 "require": {
85 ...
86 "jackalope/jackalope-doctrine-dbal": "dev-master",
87 "doctrine/phpcr-bundle": "1.0.*",
88 "doctrine/phpcr-odm": "1.0.*"
89 }
a9aa769 @dbu fixing lots of code block starts
dbu authored Oct 16, 2012
90
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
91 **Midgard**
92
93 .. code-block:: javascript
94
cad8dc4 @lsmith77 added stability dev
lsmith77 authored Dec 6, 2012
95 "minimum-stability": "dev",
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
96 "require": {
97 ...
98 "midgard/phpcr": "dev-master",
99 "doctrine/phpcr-bundle": "1.0.*",
100 "doctrine/phpcr-odm": "1.0.*"
101 }
102
fe3f13e @lsmith77 minor fixes
lsmith77 authored Dec 3, 2012
103 .. note::
1f9e667 Changes following pull request comments.
Lars Janssen authored Nov 14, 2012
104
105 For all of the above, if you are also using Doctrine ORM, make sure to use
106 ``"doctrine/orm": "2.3.*"``, otherwise composer can't resolve the dependencies as Doctrine
fe3f13e @lsmith77 minor fixes
lsmith77 authored Dec 3, 2012
107 PHPCR-ODM depends on the newer 2.3 Doctrine Commons. (Symfony2.1 standard edition uses "2.2.*".)
1f9e667 Changes following pull request comments.
Lars Janssen authored Nov 14, 2012
108
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
109 To install the above dependencies, run:
a9aa769 @dbu fixing lots of code block starts
dbu authored Oct 16, 2012
110
111 .. code-block:: bash
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
112
113 php composer.phar update
114
115 Register annotations
116 ~~~~~~~~~~~~~~~~~~~~
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
117 PHPCR-ODM uses annotations and these need to be registered in your ``app/autoload.php``
118 file. Add the following line, immediately after the last ``AnnotationRegistry::registerFile``
119 line:
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
120
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 15, 2012
121 .. code-block:: php
122
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
123 // app/autoload.php
124
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
125 // ...
126 AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');
127 // ...
128
129 Initialize bundles
130 ~~~~~~~~~~~~~~~~~~
a9aa769 @dbu fixing lots of code block starts
dbu authored Oct 16, 2012
131 Next, initialize the bundles in ``app/AppKernel.php`` by adding them to the
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
132 ``registerBundle`` method:
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
133
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 15, 2012
134 .. code-block:: php
135
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
136 // app/AppKernel.php
137
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
138 public function registerBundles()
139 {
140 $bundles = array(
141 // ...
142
143 // Doctrine PHPCR
144 new Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(),
145
146 );
147 // ...
148 }
149
150
151 Configuration
152 -------------
153 Next step is to configure the bundles.
154
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
155 PHPCR Session
156 ~~~~~~~~~~~~~
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 15, 2012
157
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
158 Basic configuration for each content repository is shown below; add the appropriate lines to your
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
159 ``app/config/config.yml``. More information on configuring this bundle can be found in the reference
160 chapter :doc:`../bundles/phpcr-odm`.
161
162 The workspace, username and password parameters are for the PHPCR repository and should not be
163 confused with possible database credentials. They come from your content repository setup. If you
164 want to use a different workspace than *default* you have to create it first in your repository.
165
166 If you want to use the PHPCR-ODM as well, please also see the next section.
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
167
168 **Jackalope with Jackrabbit**
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 15, 2012
169
170 .. configuration-block::
171
172 .. code-block:: yaml
173
174 # app/config/config.yml
175 doctrine_phpcr:
176 session:
177 backend:
178 type: jackrabbit
179 url: http://localhost:8080/server/
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
180 workspace: default
181 username: admin
182 password: admin
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
183 # odm configuration see below
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
184
185 **Jackalope with Doctrine DBAL**
186
187 .. configuration-block::
188
189 .. code-block:: yaml
190
191 # app/config/config.yml
192 doctrine_phpcr:
193 session:
194 backend:
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 15, 2012
195 type: doctrinedbal
196 connection: doctrine.dbal.default_connection
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
197 workspace: default
198 username: admin
199 password: admin
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
200 # odm configuration see below
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
201
202 .. note::
203
204 Make sure you also configure the main ``doctrine:`` section for your chosen RDBMS.
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
205 If you want to use a different than the default connection, configure it in the dbal
206 section and specify it in the connection parameter. A typical example configuration is:
207
208 doctrine:
209 dbal:
210 driver: %database_driver%
211 host: %database_host%
212 port: %database_port%
213 dbname: %database_name%
214 user: %database_user%
215 password: %database_password%
216 charset: UTF8
217
218 See `Databases and Doctrine <http://symfony.com/doc/2.1/book/doctrine.html>`_ for more information.
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
219
220 **Midgard**
221
222 .. configuration-block::
223
224 .. code-block:: yaml
225
226 # app/config/config.yml
227 doctrine_phpcr:
228 session:
229 backend:
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 15, 2012
230 type: midgard2
231 db_type: MySQL
232 db_name: midgard2_test
233 db_host: "0.0.0.0"
234 db_port: 3306
235 db_username: ""
236 db_password: ""
237 db_init: true
238 blobdir: /tmp/cmf-blobs
239 workspace: default
240 username: admin
241 password: admin
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
242 # odm configuration see below
243
244
245 Doctrine PHPCR-ODM
246 ~~~~~~~~~~~~~~~~~~
247
248 Any of the above configurations will give you a valid PHPCR session. If you want to use the
249 Object-Document manager, you need to configure it as well. The simplest is to set
250 ``auto_mapping: true`` to make the PHPCR bundle recognize documents in the ``<Bundle>/Document``
251 folder and look for mappings in ``<Bundle>/Resources/config/doctrine/<Document>.phpcr.xml`` resp.
252 ``...yml``. Otherwise you need to manually configure the mappings section. See the
253 :ref:`PHPCR-ODM configuration reference<reference-phpcr-odm-configuration>` for details.
254
255 .. configuration-block::
256
257 .. code-block:: yaml
258
259 # app/config/config.yml
260 doctrine_phpcr:
261 session:
262 ...
709571b @trompette fixed indentation
trompette authored Jan 3, 2013
263 odm:
264 auto_mapping: true
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
265
18139d7 @dbu cleaning up documentation and integrating everything that was in the …
dbu authored Jan 4, 2013
266
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
267 Setting up the content repository
268 ---------------------------------
269
270 .. _tutorials-installing-phpcr-jackrabbit:
271
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
272 **Jackalope Jackrabbit**
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
273
274 .. index:: Jackrabbit
275
276 These are the steps necessary to install Apache Jackrabbit:
277
a9aa769 @dbu fixing lots of code block starts
dbu authored Oct 16, 2012
278 - Make sure you have Java Virtual Machine installed on your box. If not, you can
279 grab one from here: http://www.java.com/en/download/manual.jsp
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
280 - Download the latest version from the `Jackrabbit Downloads page <http://jackrabbit.apache.org/downloads.html>`_
a9aa769 @dbu fixing lots of code block starts
dbu authored Oct 16, 2012
281 - Run the server. Go to the folder where you downloaded the .jar file and launch it
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
282
089c765 @lsmith77 some more cleanups and typo fixes
lsmith77 authored Oct 15, 2012
283 .. code-block:: bash
284
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
285 java -jar jackrabbit-standalone-*.jar
286
287 Going to http://localhost:8080/ should now display a Apache Jackrabbit page.
288
289 More information about `running a Jackrabbit server <https://github.com/jackalope/jackalope/wiki/Running-a-jackrabbit-server>`_
290 can be found on the Jackalope wiki.
291
292 .. _tutorials-installing-phpcr-doctrinedbal:
293
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
294 **Jackalope Doctrine DBAL**
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
295
296 .. index:: Doctrine, DBAL, RDBMS
297
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
298 Run the following commands to create the database and set up a default schema:
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
299
300 .. code-block:: bash
301
302 app/console doctrine:database:create
303 app/console doctrine:phpcr:init:dbal
304
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
305 For more information on how to configure Doctrine DBAL with Symfony2, see the
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
306 `Doctrine chapter in the Symfony2 documentation <http://symfony.com/doc/current/book/doctrine.html>`_
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
307 and the explanations in the :ref:`PHPCR reference chapter <reference-phpcr-doctrinedbal>`.
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
308
309 .. _tutorials-installing-phpcr-midgard:
310
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
311 **Midgard**
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
312
313 .. index:: Midgard, RDBMS
314
315 Midgard is a C extension that implements the PHPCR API on top of a standard RDBMS.
316
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
317 See the `official Midgard PHPCR documentation <http://midgard-project.org/phpcr/>`_.
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
318
319 Registering system node types
320 -----------------------------
8f43821 @lsmith77 lots of details, added SonataDoctrinePhpcrAdminBundle
lsmith77 authored Oct 27, 2012
321 PHPCR-ODM uses a `custom node type <https://github.com/doctrine/phpcr-odm/wiki/Custom-node-type-phpcr%3Amanaged>`_
e2449f5 More Doctrine PHPCR-ODM content-specific examples, clarifications, tw…
Lars Janssen authored Nov 11, 2012
322 to track meta information without interfering with your content. There is a command that makes it
323 trivial to register this type and the PHPCR namespace:
1fd2ef6 @dbu adding doc on phpcr-odm bundle and lots of cleanup
dbu authored Oct 15, 2012
324
325 .. code-block:: bash
326
327 php app/console doctrine:phpcr:register-system-node-types
0f2e1b2 @EmmanuelVella Add note about ValidPhpcrOdm constraint validator in tutorial
EmmanuelVella authored Jan 16, 2013
328
329 Using the ValidPhpcrOdm constraint validator
b4a0649 @dbu get rid of warning about title underline
dbu authored Jan 16, 2013
330 --------------------------------------------
0f2e1b2 @EmmanuelVella Add note about ValidPhpcrOdm constraint validator in tutorial
EmmanuelVella authored Jan 16, 2013
331
332 The bundle provides a ``ValidPhpcrOdm`` constraint validator you can use to check if your document ``Id`` or ``Nodename`` and ``Parent`` fields are correct :
333
334 .. code-block:: php
6e5dde8 @EmmanuelVella Fix typo in doc
EmmanuelVella authored Jan 16, 2013
335
0f2e1b2 @EmmanuelVella Add note about ValidPhpcrOdm constraint validator in tutorial
EmmanuelVella authored Jan 16, 2013
336 <?php
337
338 namespace Acme\DemoBundle\Document;
339
340 use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
341 use Doctrine\Bundle\PHPCRBundle\Validator\Constraints as Assert;
342
343 /**
344 * @PHPCRODM\Document
345 * @Assert\ValidPhpcrOdm
346 */
347 class MyDocument
348 {
349 /** @PHPCRODM\Id(strategy="parent") */
350 protected $id;
351
352 /** @PHPCRODM\Nodename */
353 protected $name;
354
355 /** @PHPCRODM\ParentDocument */
356 protected $parent;
357
358 ...
Something went wrong with that request. Please try again.