Skip to content

Commit 9f49497

Browse files
committed
Reviewed Configuration cookbook articles
1 parent 51af15d commit 9f49497

7 files changed

+140
-104
lines changed

cookbook/configuration/apache_router.rst

+10-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
How to Use the Apache Router
55
============================
66

7-
Symfony, while fast out of the box, also provides various ways to increase that speed with a little bit of tweaking.
8-
One of these ways is by letting Apache handle routes directly, rather than using Symfony for this task.
7+
Symfony, while fast out of the box, also provides various ways to increase that
8+
speed with a little bit of tweaking. One of these ways is by letting Apache
9+
handle routes directly, rather than using Symfony for this task.
910

1011
Change Router Configuration Parameters
1112
--------------------------------------
@@ -61,20 +62,20 @@ To test that it's working, create a very basic route for the AppBundle:
6162
# app/config/routing.yml
6263
hello:
6364
path: /hello/{name}
64-
defaults: { _controller: AppBundle:Demo:hello }
65+
defaults: { _controller: AppBundle:Default:hello }
6566
6667
.. code-block:: xml
6768
6869
<!-- app/config/routing.xml -->
6970
<route id="hello" path="/hello/{name}">
70-
<default key="_controller">AppBundle:Demo:hello</default>
71+
<default key="_controller">AppBundle:Default:hello</default>
7172
</route>
7273
7374
.. code-block:: php
7475
7576
// app/config/routing.php
7677
$collection->add('hello', new Route('/hello/{name}', array(
77-
'_controller' => 'AppBundle:Demo:hello',
78+
'_controller' => 'AppBundle:Default:hello',
7879
)));
7980
8081
Now generate the mod_rewrite rules:
@@ -93,7 +94,7 @@ Which should roughly output the following:
9394
9495
# hello
9596
RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$
96-
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello]
97+
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Default\:hello]
9798
9899
You can now rewrite ``web/.htaccess`` to use the new rules, so with this example
99100
it should look like this:
@@ -109,12 +110,13 @@ it should look like this:
109110
110111
# hello
111112
RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$
112-
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello]
113+
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Default\:hello]
113114
</IfModule>
114115
115116
.. note::
116117

117-
The procedure above should be done each time you add/change a route if you want to take full advantage of this setup.
118+
The procedure above should be done each time you add/change a route if you
119+
want to take full advantage of this setup.
118120

119121
That's it!
120122
You're now all set to use Apache routes.

cookbook/configuration/environments.rst

+20-21
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Different Environments, different Configuration Files
2020
-----------------------------------------------------
2121

2222
A typical Symfony application begins with three environments: ``dev``,
23-
``prod``, and ``test``. As discussed, each "environment" simply represents
23+
``prod``, and ``test``. As mentioned, each environment simply represents
2424
a way to execute the same codebase with different configuration. It should
2525
be no surprise then that each environment loads its own individual configuration
2626
file. If you're using the YAML configuration format, the following files
@@ -55,8 +55,8 @@ multiple environments in an elegant, powerful and transparent way.
5555

5656
Of course, in reality, each environment differs only somewhat from others.
5757
Generally, all environments will share a large base of common configuration.
58-
Opening the "dev" configuration file, you can see how this is accomplished
59-
easily and transparently:
58+
Opening the ``config_dev.yml`` configuration file, you can see how this is
59+
accomplished easily and transparently:
6060

6161
.. configuration-block::
6262

@@ -86,7 +86,8 @@ simply first imports from a central configuration file (``config.yml``).
8686
The remainder of the file can then deviate from the default configuration
8787
by overriding individual parameters. For example, by default, the ``web_profiler``
8888
toolbar is disabled. However, in the ``dev`` environment, the toolbar is
89-
activated by modifying the default value in the ``dev`` configuration file:
89+
activated by modifying the value of the ``toolbar`` option in the ``config_dev.yml``
90+
configuration file:
9091

9192
.. configuration-block::
9293

@@ -151,9 +152,9 @@ used by each is explicitly set::
151152

152153
// ...
153154

154-
As you can see, the ``prod`` key specifies that this application will run
155-
in the ``prod`` environment. A Symfony application can be executed in any
156-
environment by using this code and changing the environment string.
155+
The ``prod`` key specifies that this application will run in the ``prod``
156+
environment. A Symfony application can be executed in any environment by using
157+
this code and changing the environment string.
157158

158159
.. note::
159160

@@ -325,9 +326,7 @@ The new environment is now accessible via::
325326
certain environments, for debugging purposes, may give too much information
326327
about the application or underlying infrastructure. To be sure these environments
327328
aren't accessible, the front controller is usually protected from external
328-
IP addresses via the following code at the top of the controller:
329-
330-
.. code-block:: php
329+
IP addresses via the following code at the top of the controller::
331330

332331
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
333332
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
@@ -361,17 +360,17 @@ the directory of the environment you're using (most commonly ``dev`` while
361360
developing and debugging). While it can vary, the ``app/cache/dev`` directory
362361
includes the following:
363362

364-
* ``appDevDebugProjectContainer.php`` - the cached "service container" that
365-
represents the cached application configuration;
366-
367-
* ``appDevUrlGenerator.php`` - the PHP class generated from the routing
368-
configuration and used when generating URLs;
369-
370-
* ``appDevUrlMatcher.php`` - the PHP class used for route matching - look
371-
here to see the compiled regular expression logic used to match incoming
372-
URLs to different routes;
373-
374-
* ``twig/`` - this directory contains all the cached Twig templates.
363+
``appDevDebugProjectContainer.php``
364+
The cached "service container" that represents the cached application
365+
configuration.
366+
``appDevUrlGenerator.php``
367+
The PHP class generated from the routing configuration and used when
368+
generating URLs.
369+
``appDevUrlMatcher.php``
370+
The PHP class used for route matching - look here to see the compiled regular
371+
expression logic used to match incoming URLs to different routes.
372+
``twig/``
373+
This directory contains all the cached Twig templates.
375374

376375
.. note::
377376

cookbook/configuration/front_controllers_and_kernel.rst

+5-8
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,10 @@ There are two methods declared in the
9494
left unimplemented in :class:`Symfony\\Component\\HttpKernel\\Kernel`
9595
and thus serve as `template methods`_:
9696

97-
* :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerBundles`,
98-
which must return an array of all bundles needed to run the
99-
application;
100-
101-
* :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration`,
102-
which loads the application configuration.
97+
:method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerBundles`
98+
It must return an array of all bundles needed to run the application.
99+
:method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration`
100+
It loads the application configuration.
103101

104102
To fill these (small) blanks, your application needs to subclass the
105103
Kernel and implement these methods. The resulting class is conventionally
@@ -124,8 +122,7 @@ controller to make use of the new kernel.
124122
it might therefore make sense to add additional sub-directories,
125123
for example ``app/admin/AdminKernel.php`` and
126124
``app/api/ApiKernel.php``. All that matters is that your front
127-
controller is able to create an instance of the appropriate
128-
kernel.
125+
controller is able to create an instance of the appropriate kernel.
129126

130127
Having different ``AppKernels`` might be useful to enable different front
131128
controllers (on potentially different servers) to run parts of your application

cookbook/configuration/override_dir_structure.rst

+15-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ directory structure is:
2929
Override the ``cache`` Directory
3030
--------------------------------
3131

32-
You can override the cache directory by overriding the ``getCacheDir`` method
32+
You can change the default cache directory by overriding the ``getCacheDir`` method
3333
in the ``AppKernel`` class of you application::
3434

3535
// app/AppKernel.php
@@ -53,16 +53,16 @@ the location of the cache directory to ``app/{environment}/cache``.
5353

5454
You should keep the ``cache`` directory different for each environment,
5555
otherwise some unexpected behavior may happen. Each environment generates
56-
its own cached config files, and so each needs its own directory to store
57-
those cache files.
56+
its own cached configuration files, and so each needs its own directory to
57+
store those cache files.
5858

5959
.. _override-logs-dir:
6060

6161
Override the ``logs`` Directory
6262
-------------------------------
6363

6464
Overriding the ``logs`` directory is the same as overriding the ``cache``
65-
directory, the only difference is that you need to override the ``getLogDir``
65+
directory. The only difference is that you need to override the ``getLogDir``
6666
method::
6767

6868
// app/AppKernel.php
@@ -80,14 +80,16 @@ method::
8080

8181
Here you have changed the location of the directory to ``app/{environment}/logs``.
8282

83+
.. _override-web-directory:
84+
8385
Override the ``web`` Directory
8486
------------------------------
8587

8688
If you need to rename or move your ``web`` directory, the only thing you
8789
need to guarantee is that the path to the ``app`` directory is still correct
8890
in your ``app.php`` and ``app_dev.php`` front controllers. If you simply
8991
renamed the directory, you're fine. But if you moved it in some way, you
90-
may need to modify the paths inside these files::
92+
may need to modify these paths inside those files::
9193

9294
require_once __DIR__.'/../Symfony/app/bootstrap.php.cache';
9395
require_once __DIR__.'/../Symfony/app/AppKernel.php';
@@ -116,8 +118,8 @@ the ``extra.symfony-web-dir`` option in the ``composer.json`` file:
116118

117119
.. note::
118120

119-
If you use the AsseticBundle you need to configure this, so it can use
120-
the correct ``web`` directory:
121+
If you use the AsseticBundle you need to configure the ``read_from`` option
122+
to point to the correct ``web`` directory:
121123

122124
.. configuration-block::
123125

@@ -147,8 +149,8 @@ the ``extra.symfony-web-dir`` option in the ``composer.json`` file:
147149
'read_from' => '%kernel.root_dir%/../../public_html',
148150
));
149151
150-
Now you just need to clear the cache and dump the assets again and your application should
151-
work:
152+
Now you just need to clear the cache and dump the assets again and your
153+
application should work:
152154

153155
.. code-block:: bash
154156
@@ -159,10 +161,7 @@ Override the ``vendor`` Directory
159161
---------------------------------
160162

161163
To override the ``vendor`` directory, you need to introduce changes in the
162-
following files:
163-
164-
* ``app/autoload.php``
165-
* ``composer.json``
164+
``app/autoload.php`` and ``composer.json`` files.
166165

167166
The change in the ``composer.json`` will look like this:
168167

@@ -177,8 +176,8 @@ The change in the ``composer.json`` will look like this:
177176
...
178177
}
179178
180-
In ``app/autoload.php``, you need to modify the path leading to the ``vendor/autoload.php``
181-
file::
179+
In ``app/autoload.php``, you need to modify the path leading to the
180+
``vendor/autoload.php`` file::
182181

183182
// app/autoload.php
184183
// ...
@@ -187,5 +186,5 @@ file::
187186
.. tip::
188187

189188
This modification can be of interest if you are working in a virtual environment
190-
and cannot use NFS - for example, if you're running a Symfony app using
189+
and cannot use NFS - for example, if you're running a Symfony application using
191190
Vagrant/VirtualBox in a guest operating system.

cookbook/configuration/pdo_session_storage.rst

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
How to Use PdoSessionHandler to Store Sessions in the Database
55
==============================================================
66

7-
The default Symfony session storage writes the session information to
8-
file(s). Most medium to large websites use a database to store the session
9-
values instead of files, because databases are easier to use and scale in a
7+
The default Symfony session storage writes the session information to files.
8+
Most medium to large websites use a database to store the session values
9+
instead of files, because databases are easier to use and scale in a
1010
multi-webserver environment.
1111

1212
Symfony has a built-in solution for database session storage called
1313
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`.
14-
To use it, you just need to change some parameters in ``config.yml`` (or the
15-
configuration format of your choice):
14+
To use it, you just need to change some parameters in the main configuration file:
1615

1716
.. versionadded:: 2.1
1817
In Symfony 2.1 the class and namespace are slightly modified. You can now
@@ -120,10 +119,16 @@ configuration format of your choice):
120119
));
121120
$container->setDefinition('session.handler.pdo', $storageDefinition);
122121
123-
* ``db_table``: The name of the session table in your database
124-
* ``db_id_col``: The name of the id column in your session table (VARCHAR(255) or larger)
125-
* ``db_data_col``: The name of the value column in your session table (TEXT or CLOB)
126-
* ``db_time_col``: The name of the time column in your session table (INTEGER)
122+
These are parameters that you must configure:
123+
124+
``db_table``
125+
The name of the session table in your database.
126+
``db_id_col``
127+
The name of the id column in your session table (``VARCHAR(255)`` or larger).
128+
``db_data_col``
129+
The name of the value column in your session table (``TEXT`` or ``CLOB``).
130+
``db_time_col``:
131+
The name of the time column in your session table (``INTEGER``).
127132

128133
Sharing your Database Connection Information
129134
--------------------------------------------

cookbook/configuration/using_parameters_in_dic.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ There are special cases such as when you want, for instance, to use the
1111
debug mode. For this case there is more work to do in order
1212
to make the system understand the parameter value. By default
1313
your parameter ``%kernel.debug%`` will be treated as a
14-
simple string. Consider this example with the AcmeDemoBundle::
14+
simple string. Consider the following example::
1515

16-
// Inside Configuration class
16+
// inside Configuration class
1717
$rootNode
1818
->children()
1919
->booleanNode('logging')->defaultValue('%kernel.debug%')->end()
2020
// ...
2121
->end()
2222
;
2323

24-
// Inside the Extension class
24+
// inside the Extension class
2525
$config = $this->processConfiguration($configuration, $configs);
2626
var_dump($config['logging']);
2727

@@ -111,7 +111,7 @@ be injected with this parameter via the extension as follows::
111111
public function getConfigTreeBuilder()
112112
{
113113
$treeBuilder = new TreeBuilder();
114-
$rootNode = $treeBuilder->root('acme_demo');
114+
$rootNode = $treeBuilder->root('my_bundle');
115115

116116
$rootNode
117117
->children()
@@ -127,14 +127,14 @@ be injected with this parameter via the extension as follows::
127127

128128
And set it in the constructor of ``Configuration`` via the ``Extension`` class::
129129

130-
namespace Acme\DemoBundle\DependencyInjection;
130+
namespace AppBundle\DependencyInjection;
131131

132132
use Symfony\Component\DependencyInjection\ContainerBuilder;
133133
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
134134
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
135135
use Symfony\Component\Config\FileLocator;
136136

137-
class AcmeDemoExtension extends Extension
137+
class AppExtension extends Extension
138138
{
139139
// ...
140140

@@ -147,7 +147,7 @@ And set it in the constructor of ``Configuration`` via the ``Extension`` class::
147147
.. sidebar:: Setting the Default in the Extension
148148

149149
There are some instances of ``%kernel.debug%`` usage within a ``Configurator``
150-
class in TwigBundle and AsseticBundle, however this is because the default
150+
class in TwigBundle and AsseticBundle. However this is because the default
151151
parameter value is set by the Extension class. For example in AsseticBundle,
152152
you can find::
153153

0 commit comments

Comments
 (0)