Skip to content

Commit 95ba03b

Browse files
committed
Reorganize and expand quickstart big picture docs on environments
* Add Environments section under "Understanding the Fundamentals" to introduce environments. This uses the glossary definition as a starting point and expands on it a little. * Move the Web Profiler discussion out of Working with Environments into a separate section, and add a paragraph briefly summarizing what the profiler can do. * Improve the Working with Environments section. * Original changes from PR #2683 rebased on 2.2
1 parent 74ed0f2 commit 95ba03b

File tree

1 file changed

+86
-49
lines changed

1 file changed

+86
-49
lines changed

quick_tour/the_big_picture.rst

Lines changed: 86 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -403,54 +403,79 @@ have seen so far. All the code you write for your application is organized in
403403
bundles. In Symfony2 speak, a bundle is a structured set of files (PHP files,
404404
stylesheets, JavaScripts, images, ...) that implements a single feature (a
405405
blog, a forum, ...) and which can be easily shared with other developers. As
406-
of now, you have manipulated one bundle, ``AcmeDemoBundle``. You will learn
406+
of now, you have manipulated one bundle, AcmeDemoBundle. You will learn
407407
more about bundles in the last chapter of this tutorial.
408408

409+
Environments
410+
~~~~~~~~~~~~
411+
412+
Every Symfony application runs within an :term:`environment`. An environment
413+
is a specific set of configuration and loaded bundles, represented by a string.
414+
The same application can be run with different configurations by running the
415+
application in different environments. Symfony2 comes with three environments
416+
defined — ``dev``, ``test`` and ``prod`` — but you can create your own as well.
417+
418+
Environments are useful by allowing a single application to have a dev environment
419+
built for debugging and a production environment optimized for speed. You might
420+
also load specific bundles based on the selected environment. For example,
421+
Symfony2 comes with the WebProfilerBundle (described below), enabled only
422+
in the ``dev`` and ``test`` environments.
423+
409424
.. _quick-tour-big-picture-environments:
410425

411426
Working with Environments
412427
-------------------------
413428

414-
Now that you have a better understanding of how Symfony2 works, take a closer
415-
look at the bottom of any Symfony2 rendered page. You should notice a small
416-
bar with the Symfony2 logo. This is called the "Web Debug Toolbar" and it
417-
is the developer's best friend.
429+
Symfony2 loads configuration based on the name of the environment. Typically,
430+
you put your common configuration in ``config.yml`` and override where necessary
431+
in the configuration for each environment. For example:
418432

419-
.. image:: /images/quick_tour/web_debug_toolbar.png
420-
:align: center
421-
422-
But what you see initially is only the tip of the iceberg; click on the long
423-
hexadecimal number (the session token) to reveal yet another very useful
424-
Symfony2 debugging tool: the profiler.
433+
.. code-block:: yaml
425434
426-
.. image:: /images/quick_tour/profiler.png
427-
:align: center
435+
# app/config/config_dev.yml
436+
imports:
437+
- { resource: config.yml }
428438
429-
.. note::
439+
web_profiler:
440+
toolbar: true
441+
intercept_redirects: false
430442
431-
You can get more information quickly by hovering over the items on the
432-
Web Debug Toolbar.
443+
In this example, the ``dev`` environment loads the ``config_dev.yml`` configuration
444+
file, which itself imports the global ``config.yml`` file and then modifies it by
445+
enabling the web debug toolbar.
433446

434-
Of course, you won't want to show these tools when you deploy your application
435-
to production. That's why you will find another front controller in the
436-
``web/`` directory (``app.php``), which is optimized for the production environment.
437-
The ``AcmeDemoBundle`` is normally only available in the dev environment (see
438-
the note below), but if you were to add it to the production environment, you
439-
could go here:
447+
To make your application respond faster, Symfony2 maintains a cache under the
448+
``app/cache/`` directory. In the ``dev`` environment, this cache is flushed
449+
automatically whenever you make changes to any code or configuration. But that's
450+
not the case in the ``prod`` environment, where performance is key. That's why you
451+
should always use the development environment when developing your application.
452+
453+
Symfony2 comes with two web-accessible front controllers: ``app_dev.php``
454+
provides the ``dev`` environment, and ``app.php`` provides the ``prod`` environment.
455+
All web accesses to Symfony2 normally go through one of these front controllers.
456+
(The ``test`` environment is normally only used when running unit tests, and so
457+
doesn't have a dedicated front controller. The console tool also provides a
458+
front controller that can be used with any environment.)
459+
460+
The AcmeDemoBundle is normally only available in the dev environment, but
461+
if you were to add it (and its routes) to the production environment, you could
462+
go here:
440463

441464
.. code-block:: text
442465
443466
http://localhost/app.php/demo/hello/Fabien
444467
445-
And if you use Apache with ``mod_rewrite`` enabled, you can even omit the
446-
``app.php`` part of the URL:
468+
If instead of using php's built-in webserver, you use Apache with ``mod_rewrite``
469+
enabled and take advantage of the ``.htaccess`` file Symfony2 provides
470+
in ``web/``, you can even omit the ``app.php`` part of the URL. The default
471+
``.htaccess`` points all requests to the ``app.php`` front controller:
447472

448473
.. code-block:: text
449474
450475
http://localhost/demo/hello/Fabien
451476
452-
Last but not least, on production servers, you should point your web root
453-
directory to the ``web/`` directory to secure your installation and have an
477+
Finally, on production servers, you should point your web root directory
478+
to the ``web/`` directory to better secure your installation and have an
454479
even better looking URL:
455480

456481
.. code-block:: text
@@ -461,35 +486,47 @@ even better looking URL:
461486

462487
Note that the three URLs above are provided here only as **examples** of
463488
how a URL looks like when the production front controller is used (with or
464-
without mod_rewrite). If you actually try them in an out of the box
465-
installation of *Symfony Standard Edition* you will get a 404 error as
466-
*AcmeDemoBundle* is enabled only in dev environment and its routes imported
467-
in *app/config/routing_dev.yml*.
489+
without mod_rewrite). If you actually try them in an out-of-the-box
490+
installation of *Symfony Standard Edition*, you will get a 404 error since
491+
*AcmeDemoBundle* is enabled only in the dev environment and its routes imported
492+
from *app/config/routing_dev.yml*.
468493

469-
To make your application respond faster, Symfony2 maintains a cache under the
470-
``app/cache/`` directory. In the development environment (``app_dev.php``),
471-
this cache is flushed automatically whenever you make changes to any code or
472-
configuration. But that's not the case in the production environment
473-
(``app.php``) where performance is key. That's why you should always use
474-
the development environment when developing your application.
494+
.. _quick-tour-big-picture-web-debug-toolbar:
475495

476-
Different :term:`environments<environment>` of a given application differ
477-
only in their configuration. In fact, a configuration can inherit from another
478-
one:
496+
The Web Debug Toolbar and Profiler
497+
----------------------------------
479498

480-
.. code-block:: yaml
481499

482-
# app/config/config_dev.yml
483-
imports:
484-
- { resource: config.yml }
500+
Now that you have a better understanding of how Symfony2 works, take a closer
501+
look at the bottom of any Symfony2 rendered page. You should notice a small
502+
bar with the Symfony2 logo. This is the "Web Debug Toolbar", and it is a
503+
Symfony2 developer's best friend.
485504

486-
web_profiler:
487-
toolbar: true
488-
intercept_redirects: false
505+
.. image:: /images/quick_tour/web_debug_toolbar.png
506+
:align: center
507+
508+
What you see initially is only the tip of the iceberg; click on the long
509+
hexadecimal number (the session token) to reveal yet another very useful
510+
Symfony2 debugging tool: the profiler.
511+
512+
.. image:: /images/quick_tour/profiler.png
513+
:align: center
514+
515+
When enabled (by default in the dev and test environments), the Profiler
516+
records a great deal of information on each request made to your application.
517+
It allows you to view details of each request, including, but not limited to,
518+
GET or POST parameters and the request headers; logs; an execution timeline;
519+
information on the currently logged in user; Doctrine queries; and more.
520+
521+
Of course, it would be unwise to have these tools enabled when you deploy
522+
your application, so by default, the profiler is not enabled in the ``prod``
523+
environment. (In fact, its bundle is not even loaded).
524+
525+
.. note::
526+
527+
You can get more information quickly by hovering over the items on the
528+
Web Debug Toolbar.
489529

490-
The ``dev`` environment (which loads the ``config_dev.yml`` configuration file)
491-
imports the global ``config.yml`` file and then modifies it by, in this example,
492-
enabling the web debug toolbar.
493530

494531
Final Thoughts
495532
--------------

0 commit comments

Comments
 (0)