-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Reviewed Configuration cookbook articles #5098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,18 @@ | |
How to Use the Apache Router | ||
============================ | ||
|
||
Symfony, while fast out of the box, also provides various ways to increase that speed with a little bit of tweaking. | ||
One of these ways is by letting Apache handle routes directly, rather than using Symfony for this task. | ||
.. caution:: | ||
|
||
**Using the Apache Router is no longer considered a good practice**. | ||
The small increase obtained in the application routing performance is not | ||
worth the hassle of continuously updating the routes configuration. | ||
|
||
The Apache Router will be removed in Symfony 3 and it's highly recommended | ||
to not use it in your applications. | ||
|
||
Symfony, while fast out of the box, also provides various ways to increase that | ||
speed with a little bit of tweaking. One of these ways is by letting Apache | ||
handle routes directly, rather than using Symfony for this task. | ||
|
||
Change Router Configuration Parameters | ||
-------------------------------------- | ||
|
@@ -61,20 +71,20 @@ To test that it's working, create a very basic route for the AppBundle: | |
# app/config/routing.yml | ||
hello: | ||
path: /hello/{name} | ||
defaults: { _controller: AppBundle:Demo:hello } | ||
defaults: { _controller: AppBundle:Greet:hello } | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/routing.xml --> | ||
<route id="hello" path="/hello/{name}"> | ||
<default key="_controller">AppBundle:Demo:hello</default> | ||
<default key="_controller">AppBundle:Greet:hello</default> | ||
</route> | ||
|
||
.. code-block:: php | ||
|
||
// app/config/routing.php | ||
$collection->add('hello', new Route('/hello/{name}', array( | ||
'_controller' => 'AppBundle:Demo:hello', | ||
'_controller' => 'AppBundle:Greet:hello', | ||
))); | ||
|
||
Now generate the mod_rewrite rules: | ||
|
@@ -93,7 +103,7 @@ Which should roughly output the following: | |
|
||
# hello | ||
RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$ | ||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello] | ||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Default\:hello] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed at sha: 808383b |
||
|
||
You can now rewrite ``web/.htaccess`` to use the new rules, so with this example | ||
it should look like this: | ||
|
@@ -109,12 +119,13 @@ it should look like this: | |
|
||
# hello | ||
RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$ | ||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello] | ||
RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Default\:hello] | ||
</IfModule> | ||
|
||
.. note:: | ||
|
||
The procedure above should be done each time you add/change a route if you want to take full advantage of this setup. | ||
The procedure above should be done each time you add/change a route if you | ||
want to take full advantage of this setup. | ||
|
||
That's it! | ||
You're now all set to use Apache routes. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ Different Environments, different Configuration Files | |
----------------------------------------------------- | ||
|
||
A typical Symfony application begins with three environments: ``dev``, | ||
``prod``, and ``test``. As discussed, each "environment" simply represents | ||
``prod``, and ``test``. As mentioned, each environment simply represents | ||
a way to execute the same codebase with different configuration. It should | ||
be no surprise then that each environment loads its own individual configuration | ||
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. | |
|
||
Of course, in reality, each environment differs only somewhat from others. | ||
Generally, all environments will share a large base of common configuration. | ||
Opening the "dev" configuration file, you can see how this is accomplished | ||
easily and transparently: | ||
Opening the ``config_dev.yml`` configuration file, you can see how this is | ||
accomplished easily and transparently: | ||
|
||
.. configuration-block:: | ||
|
||
|
@@ -86,7 +86,8 @@ simply first imports from a central configuration file (``config.yml``). | |
The remainder of the file can then deviate from the default configuration | ||
by overriding individual parameters. For example, by default, the ``web_profiler`` | ||
toolbar is disabled. However, in the ``dev`` environment, the toolbar is | ||
activated by modifying the default value in the ``dev`` configuration file: | ||
activated by modifying the value of the ``toolbar`` option in the ``config_dev.yml`` | ||
configuration file: | ||
|
||
.. configuration-block:: | ||
|
||
|
@@ -151,9 +152,9 @@ used by each is explicitly set:: | |
|
||
// ... | ||
|
||
As you can see, the ``prod`` key specifies that this application will run | ||
in the ``prod`` environment. A Symfony application can be executed in any | ||
environment by using this code and changing the environment string. | ||
The ``prod`` key specifies that this application will run in the ``prod`` | ||
environment. A Symfony application can be executed in any environment by using | ||
this code and changing the environment string. | ||
|
||
.. note:: | ||
|
||
|
@@ -325,9 +326,7 @@ The new environment is now accessible via:: | |
certain environments, for debugging purposes, may give too much information | ||
about the application or underlying infrastructure. To be sure these environments | ||
aren't accessible, the front controller is usually protected from external | ||
IP addresses via the following code at the top of the controller: | ||
|
||
.. code-block:: php | ||
IP addresses via the following code at the top of the controller:: | ||
|
||
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) { | ||
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); | ||
|
@@ -361,17 +360,20 @@ the directory of the environment you're using (most commonly ``dev`` while | |
developing and debugging). While it can vary, the ``app/cache/dev`` directory | ||
includes the following: | ||
|
||
* ``appDevDebugProjectContainer.php`` - the cached "service container" that | ||
represents the cached application configuration; | ||
``appDevDebugProjectContainer.php`` | ||
The cached "service container" that represents the cached application | ||
configuration. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add blank lines between entries for clarity. |
||
|
||
* ``appDevUrlGenerator.php`` - the PHP class generated from the routing | ||
configuration and used when generating URLs; | ||
``appDevUrlGenerator.php`` | ||
The PHP class generated from the routing configuration and used when | ||
generating URLs. | ||
|
||
* ``appDevUrlMatcher.php`` - the PHP class used for route matching - look | ||
here to see the compiled regular expression logic used to match incoming | ||
URLs to different routes; | ||
``appDevUrlMatcher.php`` | ||
The PHP class used for route matching - look here to see the compiled regular | ||
expression logic used to match incoming URLs to different routes. | ||
|
||
* ``twig/`` - this directory contains all the cached Twig templates. | ||
``twig/`` | ||
This directory contains all the cached Twig templates. | ||
|
||
.. note:: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,14 @@ | |
How to Use PdoSessionHandler to Store Sessions in the Database | ||
============================================================== | ||
|
||
The default Symfony session storage writes the session information to | ||
file(s). Most medium to large websites use a database to store the session | ||
values instead of files, because databases are easier to use and scale in a | ||
The default Symfony session storage writes the session information to files. | ||
Most medium to large websites use a database to store the session values | ||
instead of files, because databases are easier to use and scale in a | ||
multi-webserver environment. | ||
|
||
Symfony has a built-in solution for database session storage called | ||
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`. | ||
To use it, you just need to change some parameters in ``config.yml`` (or the | ||
configuration format of your choice): | ||
To use it, you just need to change some parameters in the main configuration file: | ||
|
||
.. versionadded:: 2.1 | ||
In Symfony 2.1 the class and namespace are slightly modified. You can now | ||
|
@@ -120,10 +119,19 @@ configuration format of your choice): | |
)); | ||
$container->setDefinition('session.handler.pdo', $storageDefinition); | ||
|
||
* ``db_table``: The name of the session table in your database | ||
* ``db_id_col``: The name of the id column in your session table (VARCHAR(255) or larger) | ||
* ``db_data_col``: The name of the value column in your session table (TEXT or CLOB) | ||
* ``db_time_col``: The name of the time column in your session table (INTEGER) | ||
These are parameters that you must configure: | ||
|
||
``db_table`` | ||
The name of the session table in your database. | ||
|
||
``db_id_col`` | ||
The name of the id column in your session table (``VARCHAR(255)`` or larger). | ||
|
||
``db_data_col`` | ||
The name of the value column in your session table (``TEXT`` or ``CLOB``). | ||
|
||
``db_time_col``: | ||
The name of the time column in your session table (``INTEGER``). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @weaverryan IIRC, we need to make sure that this is updated properly when merged into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. absolutely right! I'm guessing I'll get a conflict anyways - that's a good reminder ;) |
||
|
||
Sharing your Database Connection Information | ||
-------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ApacheUrlMatcher
as well as theApacheMatcherDumper
are deprecated. Should we add warning about this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think we should - I think this whole "article" is deprecated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a note about not using Apache Router in aedaccd. Please tell me if it's OK. Thanks.