Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb90be4

Browse files
committed
Merge pull request#2823 from jbafford/big-picture-environments-22
Improve Quick Tour "Big Picture" section and expand Environments docs
2 parentse862ef6 +202171b commitbb90be4

File tree

2 files changed

+90
-44
lines changed

2 files changed

+90
-44
lines changed

‎book/page_creation.rst‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,42 @@ HTTP response.
2222
Symfony2 follows this philosophy and provides you with tools and conventions
2323
to keep your application organized as it grows in users and complexity.
2424

25+
..index::
26+
single: Page creation; Environments & Front Controllers
27+
28+
.. _page-creation-environments:
29+
30+
Environments & Front Controllers
31+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32+
33+
Every Symfony application runs within an:term:`environment`. An environment
34+
is a specific set of configuration and loaded bundles, represented by a string.
35+
The same application can be run with different configurations by running the
36+
application in different environments. Symfony2 comes with three environments
37+
defined — ``dev``, ``test`` and ``prod`` — but you can create your own as well.
38+
39+
Environments are useful by allowing a single application to have a dev environment
40+
built for debugging and a production environment optimized for speed. You might
41+
also load specific bundles based on the selected environment. For example,
42+
Symfony2 comes with the WebProfilerBundle (described below), enabled only
43+
in the ``dev`` and ``test`` environments.
44+
45+
Symfony2 comes with two web-accessible front controllers: ``app_dev.php``
46+
provides the ``dev`` environment, and ``app.php`` provides the ``prod`` environment.
47+
All web accesses to Symfony2 normally go through one of these front controllers.
48+
(The ``test`` environment is normally only used when running unit tests, and so
49+
doesn't have a dedicated front controller. The console tool also provides a
50+
front controller that can be used with any environment.)
51+
52+
When the front controller initializes the kernel, it provides two parameters:
53+
the environment, and also whether the kernel should run in debug mode.
54+
To make your application respond faster, Symfony2 maintains a cache under the
55+
``app/cache/`` directory. When in debug mode is enabled (such as ``app_dev.php``
56+
does by default), this cache is flushed automatically whenever you make changes
57+
to any code or configuration. When running in debug mode, Symfony2 runs
58+
slower, but your changes are reflected without having to manually clear the
59+
cache.
60+
2561
..index::
2662
single: Page creation; Example
2763

‎quick_tour/the_big_picture.rst‎

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ 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

409409
.. _quick-tour-big-picture-environments:
@@ -413,13 +413,13 @@ Working with Environments
413413

414414
Now that you have a better understanding of how Symfony2 works, take a closer
415415
look at the bottom of any Symfony2 rendered page. You should notice a small
416-
bar with the Symfony2 logo. This iscalledthe "Web Debug Toolbar" and it
417-
is the developer's best friend.
416+
bar with the Symfony2 logo. This is the "Web Debug Toolbar", and it is a
417+
Symfony2 developer's best friend.
418418

419419
..image::/images/quick_tour/web_debug_toolbar.png
420420
:align:center
421421

422-
But whatyou see initially is only the tip of the iceberg; click on the long
422+
Whatyou see initially is only the tip of the iceberg; click on the
423423
hexadecimal number (the session token) to reveal yet another very useful
424424
Symfony2 debugging tool: the profiler.
425425

@@ -428,29 +428,63 @@ Symfony2 debugging tool: the profiler.
428428

429429
..note::
430430

431-
You can get more information quickly by hovering over the items on the
432-
Web Debug Toolbar.
431+
You can also get more information quickly by hovering over the items
432+
on the Web Debug Toolbar, or clicking them to go to their respective
433+
pages in the profiler.
434+
435+
When loaded (by default in the dev and test environments), and enabled
436+
(by default, only in the dev environment) the Profiler provides an interface
437+
to view a great deal of information recorded on each request made to your
438+
application. It allows you to view details of each request, including, but
439+
not limited to, GET or POST parameters and the request headers; logs; an
440+
execution timeline; information on the currently logged in user; Doctrine
441+
queries; and more.
442+
443+
Of course, it would be unwise to have these tools enabled when you deploy
444+
your application, so by default, the profiler is not enabled in the ``prod``
445+
environment. (In fact, its bundle is not even loaded).
446+
447+
Symfony2 loads configuration based on the name of the environment. Typically,
448+
you put your common configuration in ``config.yml`` and override where necessary
449+
in the configuration for each environment. For example:
433450

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:
451+
..code-block::yaml
452+
453+
# app/config/config_dev.yml
454+
imports:
455+
-{ resource: config.yml }
456+
457+
web_profiler:
458+
toolbar:true
459+
intercept_redirects:false
460+
461+
In this example, the ``dev`` environment loads the ``config_dev.yml`` configuration
462+
file, which itself imports the global ``config.yml`` file and then modifies it by
463+
enabling the web debug toolbar.
464+
465+
..tip::
466+
467+
For more details on environments, see ":ref:`Environments & Front Controllers<page-creation-environments>`".
468+
469+
The AcmeDemoBundle is normally only available in the dev environment, but
470+
if you were to add it (and its routes) to the production environment, you could
471+
go here:
440472

441473
..code-block::text
442474
443475
http://localhost/app.php/demo/hello/Fabien
444476
445-
And if you use Apache with ``mod_rewrite`` enabled, you can even omit the
446-
``app.php`` part of the URL:
477+
If instead of using php's built-in webserver, you use Apache with ``mod_rewrite``
478+
enabled and take advantage of the ``.htaccess`` file Symfony2 provides
479+
in ``web/``, you can even omit the ``app.php`` part of the URL. The default
480+
``.htaccess`` points all requests to the ``app.php`` front controller:
447481

448482
..code-block::text
449483
450484
http://localhost/demo/hello/Fabien
451485
452-
Last but not least, on production servers, you should point your web root
453-
directoryto the ``web/`` directory to secure your installation and have an
486+
Finally, on production servers, you should point your web root directory
487+
to the ``web/`` directory to better secure your installation and have an
454488
even better looking URL:
455489

456490
..code-block::text
@@ -461,35 +495,11 @@ even better looking URL:
461495

462496
Note that the three URLs above are provided here only as **examples** of
463497
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*.
468-
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.
475-
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:
479-
480-
..code-block::yaml
498+
without mod_rewrite). If you actually try them in an out-of-the-box
499+
installation of *Symfony Standard Edition*, you will get a 404 error since
500+
*AcmeDemoBundle* is enabled only in the dev environment and its routes imported
501+
from *app/config/routing_dev.yml*.
481502

482-
# app/config/config_dev.yml
483-
imports:
484-
-{ resource: config.yml }
485-
486-
web_profiler:
487-
toolbar:true
488-
intercept_redirects:false
489-
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.
493503

494504
Final Thoughts
495505
--------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp