Skip to content

Commit 84e6e7f

Browse files
committed
minor #4114 [Book] consistent and complete config examples (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Book] consistent and complete config examples | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | Make configuration examples in the book consistent throughout the different configuration formats. Also fixing several syntax issues. Commits ------- 96fb64f [Book] consistent and complete config examples
2 parents 03fcab1 + 96fb64f commit 84e6e7f

15 files changed

+478
-239
lines changed

Diff for: book/controller.rst

+12
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@ to the controller:
170170
.. code-block:: php
171171
172172
// app/config/routing.php
173+
use Symfony\Component\Routing\Route;
174+
use Symfony\Component\Routing\RouteCollection;
175+
176+
$collection = new RouteCollection();
173177
$collection->add('hello', new Route('/hello/{name}', array(
174178
'_controller' => 'AcmeHelloBundle:Hello:index',
175179
)));
176180
181+
return $collection;
182+
177183
Going to ``/hello/ryan`` now executes the ``HelloController::indexAction()``
178184
controller and passes in ``ryan`` for the ``$name`` variable. Creating a
179185
"page" means simply creating a controller method and associated route.
@@ -257,11 +263,17 @@ example:
257263
.. code-block:: php
258264
259265
// app/config/routing.php
266+
use Symfony\Component\Routing\Route;
267+
use Symfony\Component\Routing\RouteCollection;
268+
269+
$collection = new RouteCollection();
260270
$collection->add('hello', new Route('/hello/{firstName}/{lastName}', array(
261271
'_controller' => 'AcmeHelloBundle:Hello:index',
262272
'color' => 'green',
263273
)));
264274
275+
return $collection;
276+
265277
The controller for this can take several arguments::
266278

267279
public function indexAction($firstName, $lastName, $color)

Diff for: book/doctrine.rst

+45-46
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,16 @@ information. By convention, this information is usually configured in an
8585
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8686
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
8787
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
88-
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
88+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
8989
9090
<doctrine:config>
9191
<doctrine:dbal
9292
driver="%database_driver%"
9393
host="%database_host%"
9494
dbname="%database_name%"
9595
user="%database_user%"
96-
password="%database_password%"
97-
/>
96+
password="%database_password%" />
9897
</doctrine:config>
99-
10098
</container>
10199
102100
.. code-block:: php
@@ -175,16 +173,14 @@ for you:
175173
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
176174
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
177175
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
178-
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
179-
180-
<doctrine:config
181-
driver="pdo_sqlite"
182-
path="%kernel.root_dir%/sqlite.db"
183-
charset="UTF-8"
184-
>
185-
<!-- ... -->
186-
</doctrine:config>
176+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
187177
178+
<doctrine:config>
179+
<doctrine:dbal
180+
driver="pdo_sqlite"
181+
path="%kernel.root_dir%/sqlite.db"
182+
charset="UTF-8" />
183+
</doctrine:config>
188184
</container>
189185
190186
.. code-block:: php
@@ -319,17 +315,17 @@ in a number of different formats including YAML, XML or directly inside the
319315
<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->
320316
<?xml version="1.0" encoding="UTF-8" ?>
321317
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
322-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
323-
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
324-
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
318+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
319+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
320+
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
325321
326322
<entity name="Acme\StoreBundle\Entity\Product" table="product">
327-
<id name="id" type="integer" column="id">
323+
<id name="id" type="integer">
328324
<generator strategy="AUTO" />
329325
</id>
330-
<field name="name" column="name" type="string" length="100" />
331-
<field name="price" column="price" type="decimal" scale="2" />
332-
<field name="description" column="description" type="text" />
326+
<field name="name" type="string" length="100" />
327+
<field name="price" type="decimal" scale="2" />
328+
<field name="description" type="text" />
333329
</entity>
334330
</doctrine-mapping>
335331
@@ -826,13 +822,15 @@ To do this, add the name of the repository class to your mapping definition:
826822
<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->
827823
<?xml version="1.0" encoding="UTF-8" ?>
828824
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
829-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
830-
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
831-
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
825+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
826+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
827+
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
828+
829+
<entity
830+
name="Acme\StoreBundle\Entity\Product"
831+
repository-class="Acme\StoreBundle\Entity\ProductRepository">
832832
833-
<entity name="Acme\StoreBundle\Entity\Product"
834-
repository-class="Acme\StoreBundle\Entity\ProductRepository">
835-
<!-- ... -->
833+
<!-- ... -->
836834
</entity>
837835
</doctrine-mapping>
838836
@@ -945,17 +943,18 @@ To relate the ``Category`` and ``Product`` entities, start by creating a
945943
.. code-block:: xml
946944
947945
<!-- src/Acme/StoreBundle/Resources/config/doctrine/Category.orm.xml -->
946+
<?xml version="1.0" encoding="UTF-8" ?>
948947
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
949948
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
950949
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
951-
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
950+
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
952951
953952
<entity name="Acme\StoreBundle\Entity\Category">
954953
<!-- ... -->
955-
<one-to-many field="products"
954+
<one-to-many
955+
field="products"
956956
target-entity="Product"
957-
mapped-by="category"
958-
/>
957+
mapped-by="category" />
959958
960959
<!--
961960
don't forget to init the collection in
@@ -1023,22 +1022,21 @@ object, you'll want to add a ``$category`` property to the ``Product`` class:
10231022
.. code-block:: xml
10241023
10251024
<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->
1025+
<?xml version="1.0" encoding="UTF-8" ?>
10261026
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
10271027
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10281028
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
1029-
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
1029+
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
10301030
10311031
<entity name="Acme\StoreBundle\Entity\Product">
10321032
<!-- ... -->
1033-
<many-to-one field="category"
1033+
<many-to-one
1034+
field="category"
10341035
target-entity="Category"
10351036
inversed-by="products"
1036-
join-column="category"
1037-
>
1038-
<join-column
1039-
name="category_id"
1040-
referenced-column-name="id"
1041-
/>
1037+
join-column="category">
1038+
1039+
<join-column name="category_id" referenced-column-name="id" />
10421040
</many-to-one>
10431041
</entity>
10441042
</doctrine-mapping>
@@ -1306,6 +1304,8 @@ the current date, only when the entity is first persisted (i.e. inserted):
13061304

13071305
.. code-block:: php-annotations
13081306
1307+
// src/Acme/StoreBundle/Entity/Product.php
1308+
13091309
/**
13101310
* @ORM\PrePersist
13111311
*/
@@ -1328,16 +1328,15 @@ the current date, only when the entity is first persisted (i.e. inserted):
13281328
<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->
13291329
<?xml version="1.0" encoding="UTF-8" ?>
13301330
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
1331-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1332-
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
1333-
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
1331+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1332+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
1333+
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
13341334
13351335
<entity name="Acme\StoreBundle\Entity\Product">
1336-
<!-- ... -->
1337-
<lifecycle-callbacks>
1338-
<lifecycle-callback type="prePersist"
1339-
method="setCreatedAtValue" />
1340-
</lifecycle-callbacks>
1336+
<!-- ... -->
1337+
<lifecycle-callbacks>
1338+
<lifecycle-callback type="prePersist" method="setCreatedAtValue" />
1339+
</lifecycle-callbacks>
13411340
</entity>
13421341
</doctrine-mapping>
13431342

Diff for: book/forms.rst

+15-14
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ corresponding to the ``task`` and ``dueDate`` properties of the ``Task`` class.
129129
You've also assigned each a "type" (e.g. ``text``, ``date``), which, among
130130
other things, determines which HTML form tag(s) is rendered for that field.
131131

132-
Finally, you added a submit button with a custom label for submitting the form to
132+
Finally, you added a submit button with a custom label for submitting the form to
133133
the server.
134134

135135
.. versionadded:: 2.3
@@ -1126,20 +1126,21 @@ easy to use in your application.
11261126
<?xml version="1.0" encoding="UTF-8" ?>
11271127
<container xmlns="http://symfony.com/schema/dic/services"
11281128
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1129-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd>
1129+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
1130+
11301131
<services>
1131-
<service id="acme_demo.form.type.task"
1132-
class="Acme\TaskBundle\Form\Type\TaskType">
1133-
<tag name="form.type" alias="task" />
1134-
</service>
1132+
<service
1133+
id="acme_demo.form.type.task"
1134+
class="Acme\TaskBundle\Form\Type\TaskType">
1135+
1136+
<tag name="form.type" alias="task" />
1137+
</service>
11351138
</services>
11361139
</container>
11371140
11381141
.. code-block:: php
11391142
11401143
// src/Acme/TaskBundle/Resources/config/services.php
1141-
use Symfony\Component\DependencyInjection\Definition;
1142-
11431144
$container
11441145
->register(
11451146
'acme_demo.form.type.task',
@@ -1590,13 +1591,13 @@ file:
15901591
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15911592
xmlns:twig="http://symfony.com/schema/dic/twig"
15921593
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
1593-
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
1594+
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
15941595
15951596
<twig:config>
1596-
<twig:form>
1597-
<twig:resource>AcmeTaskBundle:Form:fields.html.twig</twig:resource>
1598-
</twig:form>
1599-
<!-- ... -->
1597+
<twig:form>
1598+
<twig:resource>AcmeTaskBundle:Form:fields.html.twig</twig:resource>
1599+
</twig:form>
1600+
<!-- ... -->
16001601
</twig:config>
16011602
</container>
16021603
@@ -1676,7 +1677,7 @@ file:
16761677
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16771678
xmlns:framework="http://symfony.com/schema/dic/symfony"
16781679
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
1679-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1680+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
16801681
16811682
<framework:config>
16821683
<framework:templating>

Diff for: book/http_cache.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,7 @@ First, to use ESI, be sure to enable it in your application configuration:
872872
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
873873
xmlns:framework="http://symfony.com/schema/dic/symfony"
874874
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
875-
http://symfony.com/schema/dic/symfony
876-
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
875+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
877876
878877
<framework:config>
879878
<!-- ... -->
@@ -886,7 +885,7 @@ First, to use ESI, be sure to enable it in your application configuration:
886885
// app/config/config.php
887886
$container->loadFromExtension('framework', array(
888887
// ...
889-
'esi' => array('enabled' => true),
888+
'esi' => array('enabled' => true),
890889
));
891890
892891
Now, suppose you have a page that is relatively static, except for a news
@@ -994,8 +993,9 @@ that must be enabled in your configuration:
994993
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
995994
xmlns:doctrine="http://symfony.com/schema/dic/framework"
996995
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
997-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
996+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
998997
998+
<!-- ... -->
999999
<framework:config>
10001000
<framework:fragments path="/_fragment" />
10011001
</framework:config>

Diff for: book/http_fundamentals.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ by adding an entry for ``/contact`` to your routing configuration file:
429429
430430
.. code-block:: xml
431431
432+
<!-- app/config/config.xml -->
432433
<?xml version="1.0" encoding="UTF-8" ?>
433434
<routes xmlns="http://symfony.com/schema/routing"
434435
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -443,8 +444,8 @@ by adding an entry for ``/contact`` to your routing configuration file:
443444
.. code-block:: php
444445
445446
// app/config/routing.php
446-
use Symfony\Component\Routing\RouteCollection;
447447
use Symfony\Component\Routing\Route;
448+
use Symfony\Component\Routing\RouteCollection;
448449
449450
$collection = new RouteCollection();
450451
$collection->add('contact', new Route('/contact', array(

Diff for: book/internals.rst

+10-13
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ the configuration for the development environment:
578578
xmlns:framework="http://symfony.com/schema/dic/symfony"
579579
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
580580
http://symfony.com/schema/dic/webprofiler http://symfony.com/schema/dic/webprofiler/webprofiler-1.0.xsd
581-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
581+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
582582
583583
<!-- load the profiler -->
584584
<framework:config>
@@ -588,9 +588,7 @@ the configuration for the development environment:
588588
<!-- enable the web profiler -->
589589
<webprofiler:config
590590
toolbar="true"
591-
intercept-redirects="true"
592-
verbose="true"
593-
/>
591+
intercept-redirects="true" />
594592
</container>
595593
596594
.. code-block:: php
@@ -604,7 +602,6 @@ the configuration for the development environment:
604602
$container->loadFromExtension('web_profiler', array(
605603
'toolbar' => true,
606604
'intercept_redirects' => true,
607-
'verbose' => true,
608605
));
609606
610607
When ``only_exceptions`` is set to ``true``, the profiler only collects data
@@ -634,18 +631,18 @@ If you enable the web profiler, you also need to mount the profiler routes:
634631
635632
<import
636633
resource="@WebProfilerBundle/Resources/config/routing/profiler.xml"
637-
prefix="/_profiler"
638-
/>
634+
prefix="/_profiler" />
639635
</routes>
640636
641637
.. code-block:: php
642638
643-
$collection->addCollection(
644-
$loader->import(
645-
"@WebProfilerBundle/Resources/config/routing/profiler.xml"
646-
),
647-
'/_profiler'
648-
);
639+
use Symfony\Component\Routing\RouteCollection;
640+
641+
$profiler = $loader->import('@WebProfilerBundle/Resources/config/routing/profiler.xml');
642+
$profiler->addPrefix('/_profiler');
643+
644+
$collection = new RouteCollection();
645+
$collection->addCollection($profiler);
649646
650647
As the profiler adds some overhead, you might want to enable it only under
651648
certain circumstances in the production environment. The ``only_exceptions``

0 commit comments

Comments
 (0)