Skip to content

Commit 72072e9

Browse files
committed
[symfony#2823] Complete re-reading of the big picture quick tour document
* Making things shorter where possible * Being more consistent in web server setup and URLs * Improving language, wording, etc
1 parent 35db202 commit 72072e9

File tree

2 files changed

+93
-123
lines changed

2 files changed

+93
-123
lines changed

components/http_foundation/introduction.rst

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ You can install the component in 2 different ways:
2424
* Use the official Git repository (https://github.com/symfony/HttpFoundation);
2525
* :doc:`Install it via Composer </components/using_components>` (``symfony/http-foundation`` on `Packagist`_).
2626

27+
.. _component-http-foundation-request:
28+
2729
Request
2830
-------
2931

@@ -267,6 +269,8 @@ request information. Have a look at
267269
:class:`the Request API<Symfony\\Component\\HttpFoundation\\Request>`
268270
for more information about them.
269271

272+
.. _component-http-foundation-response:
273+
270274
Response
271275
--------
272276

quick_tour/the_big_picture.rst

+89-123
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,17 @@ Apache) with PHP 5.3.3 or higher.
2121

2222
.. tip::
2323

24-
If you have PHP 5.4, you could use the built-in web server. The built-in
25-
server should be used only for development purpose, but it can help you
26-
to start your project quickly and easily.
24+
If you have PHP 5.4, you could use the built-in web server to start trying
25+
things out. We'll tell you how to start the built-in web server
26+
:ref:`after downloading Symfony<quick-tour-big-picture-built-in-server>`.
2727

28-
Just use this command to launch the server:
29-
30-
.. code-block:: bash
31-
32-
$ php -S localhost:80 -t /path/to/www
33-
34-
where "/path/to/www" is the path to some directory on your machine that
35-
you'll extract Symfony into so that the eventual URL to your application
36-
is "http://localhost/Symfony/app_dev.php". You can also extract Symfony
37-
first and then start the web server in the Symfony "web" directory. If
38-
you do this, the URL to your application will be "http://localhost/app_dev.php".
39-
40-
Ready? Start by downloading the "`Symfony2 Standard Edition`_", a Symfony
28+
Ready? Start by downloading the "`Symfony2 Standard Edition`_": a Symfony
4129
:term:`distribution` that is preconfigured for the most common use cases and
4230
also contains some code that demonstrates how to use Symfony2 (get the archive
4331
with the *vendors* included to get started even faster).
4432

45-
After unpacking the archive under your web server root directory, you should
33+
After unpacking the archive under your web server root directory (if you'll
34+
use the built-in PHP web server, you can unpack it anywhere), you should
4635
have a ``Symfony/`` directory that looks like this:
4736

4837
.. code-block:: text
@@ -71,35 +60,40 @@ have a ``Symfony/`` directory that looks like this:
7160
7261
.. note::
7362

74-
If you are familiar with Composer, you can run the following command
75-
instead of downloading the archive:
63+
If you are familiar with `Composer`_, you can download Composer and then
64+
run the following command instead of downloading the archive (replacing
65+
``2.2.0`` with the latest Symfony release like ``2.2.1``):
7666

7767
.. code-block:: bash
7868
79-
$ composer.phar create-project symfony/framework-standard-edition path/to/install 2.2.0
69+
$ php composer.phar create-project symfony/framework-standard-edition Symfony 2.2.0
8070
81-
# remove the Git history
82-
$ rm -rf .git
71+
.. _`quick-tour-big-picture-built-in-server`:
8372

84-
For an exact version, replace `2.2.0` with the latest Symfony version
85-
(e.g. 2.1.1). For details, see the `Symfony Installation Page`_
73+
If you have PHP 5.4, you can use the built-in web server:
8674

87-
.. tip::
75+
.. code-block:: bash
8876
89-
If you have PHP 5.4, you can use the built-in web server:
77+
# check your PHP CLI configuration
78+
$ php php app/check.php
9079
91-
.. code-block:: bash
80+
# run the built-in web server
81+
$ php php app/console server:run
9282
93-
# check your PHP CLI configuration
94-
$ php ./app/check.php
83+
Then the URL to your application will be "http://localhost:8000/app_dev.php"
9584

96-
# run the built-in web server
97-
$ php ./app/console server:run
85+
The built-in server should be used only for development purpose, but it
86+
can help you to start your project quickly and easily.
9887

99-
Then the URL to your application will be "http://localhost:8000/app_dev.php"
88+
If you're using a traditional web server like Apache, your URL depends on
89+
your configuration. If you've unzipped Symfony under your web root into a
90+
``Symfony`` directory, then the URL to your application will be:
91+
"http://localhost/Symfony/web/app_dev.php".
10092

101-
The built-in server should be used only for development purpose, but it
102-
can help you to start your project quickly and easily.
93+
.. note::
94+
95+
Read more in our :doc:`/cookbook/configuration/web_server_configuration`
96+
section.
10397

10498
Checking the Configuration
10599
--------------------------
@@ -114,31 +108,13 @@ URL to see the diagnostics for your machine:
114108
115109
.. note::
116110

117-
All of the example URLs assume that you've downloaded and unzipped Symfony
118-
directly into the web server web root. If you've followed the directions
119-
above and unzipped the `Symfony` directory into your web root, then add
120-
`/Symfony/web` after `localhost` for all the URLs you see:
121-
122-
.. code-block:: text
123-
124-
http://localhost/Symfony/web/config.php
125-
126-
.. note::
127-
128-
All of the example URLs assume that you've downloaded and unzipped ``Symfony``
129-
directly into the web server web root. If you've followed the directions
130-
above and done this, then add ``/Symfony/web`` after ``localhost`` for all
131-
the URLs you see:
132-
133-
.. code-block:: text
134-
135-
http://localhost/Symfony/web/config.php
136-
137-
To get nice and short urls you should point the document root of your
138-
webserver or virtual host to the ``Symfony/web/`` directory. In that
139-
case, your URLs will look like ``http://localhost/config.php`` or
140-
``http://site.local/config.php``, if you created a virtual host to a
141-
local domain called, for example, ``site.local``.
111+
All of the example URLs assume you've setup your web server to point
112+
directly to the ``web/`` directory of your new project, which is different
113+
and a bit more advanced than the process shown above. So, the URL on your
114+
machine will vary - e.g. ``http://localhost:8000/config.php``
115+
or ``http://localhost/Symfony/web/config.php``. See the
116+
:ref:`above section<quick-tour-big-picture-built-in-server>` for details
117+
on what your URL should be and use it below in all of the examples.
142118

143119
If there are any outstanding issues listed, correct them. You might also tweak
144120
your configuration by following any given recommendations. When everything is
@@ -196,8 +172,8 @@ Routing
196172
~~~~~~~
197173

198174
Symfony2 routes the request to the code that handles it by trying to match the
199-
requested URL against some configured paths. By default, these paths
200-
(called routes) are defined in the ``app/config/routing.yml`` configuration
175+
requested URL (i.e. the virtual path) against some configured paths. By default,
176+
these paths (called routes) are defined in the ``app/config/routing.yml`` configuration
201177
file. When you're in the ``dev`` :ref:`environment<quick-tour-big-picture-environments>` -
202178
indicated by the app_**dev**.php front controller - the ``app/config/routing_dev.yml``
203179
configuration file is also loaded. In the Standard Edition, the routes to
@@ -224,21 +200,21 @@ will be executed. In the next section, you'll learn exactly what that means.
224200

225201
.. tip::
226202

227-
The Symfony2 Standard Edition uses `YAML`_ for its configuration files,
228-
but Symfony2 also supports XML, PHP, and annotations natively. The
229-
different formats are compatible and may be used interchangeably within an
230-
application. Also, the performance of your application does not depend on
231-
the configuration format you choose as everything is cached on the very
232-
first request.
203+
The Symfony2 Standard Edition uses :doc:`YAML</components/yaml/yaml_format>`
204+
for its configuration files, but Symfony2 also supports XML, PHP, and
205+
annotations natively. The different formats are compatible and may be
206+
used interchangeably within an application. Also, the performance of
207+
your application does not depend on the configuration format you choose
208+
as everything is cached on the very first request.
233209

234210
Controllers
235211
~~~~~~~~~~~
236212

237213
A controller is a fancy name for a PHP function or method that handles incoming
238214
*requests* and returns *responses* (often HTML code). Instead of using the
239215
PHP global variables and functions (like ``$_GET`` or ``header()``) to manage
240-
these HTTP messages, Symfony uses objects: :class:`Symfony\\Component\\HttpFoundation\\Request`
241-
and :class:`Symfony\\Component\\HttpFoundation\\Response`. The simplest possible
216+
these HTTP messages, Symfony uses objects: :ref:`Request<component-http-foundation-request>`
217+
and :ref:`Response<component-http-foundation-response>`. The simplest possible
242218
controller might create the response by hand, based on the request::
243219

244220
use Symfony\Component\HttpFoundation\Response;
@@ -281,11 +257,10 @@ the ``Acme\DemoBundle\Controller\WelcomeController`` class::
281257

282258
The ``WelcomeController`` class extends the built-in ``Controller`` class,
283259
which provides useful shortcut methods, like the
284-
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::render`
285-
method that loads and renders a template
286-
(``AcmeDemoBundle:Welcome:index.html.twig``). The returned value is a Response
287-
object populated with the rendered content. So, if the needs arise, the
288-
Response can be tweaked before it is sent to the browser::
260+
:ref:`render()<controller-rendering-templates>` method that loads and renders
261+
a template (``AcmeDemoBundle:Welcome:index.html.twig``). The returned value
262+
is a Response object populated with the rendered content. So, if the need
263+
arises, the Response can be tweaked before it is sent to the browser::
289264

290265
public function indexAction()
291266
{
@@ -308,10 +283,9 @@ return the contents of a JPG image with a ``Content-Type`` header of ``image/jpg
308283
everything about Symfony2 controllers.
309284

310285
The template name, ``AcmeDemoBundle:Welcome:index.html.twig``, is the template
311-
*logical name* and it references the
312-
``Resources/views/Welcome/index.html.twig`` file inside the ``AcmeDemoBundle``
313-
(located at ``src/Acme/DemoBundle``). The bundles section below will explain
314-
why this is useful.
286+
*logical name* and it references the ``Resources/views/Welcome/index.html.twig``
287+
file inside the ``AcmeDemoBundle`` (located at ``src/Acme/DemoBundle``).
288+
The `Bundles`_ section below will explain why this is useful.
315289

316290
Now, take a look at the routing configuration again and find the ``_demo``
317291
key:
@@ -355,9 +329,9 @@ you can see, its value can be retrieved through the ``$name`` method argument.
355329

356330
.. note::
357331

358-
Even if annotations are not natively supported by PHP, you use them
359-
extensively in Symfony2 as a convenient way to configure the framework
360-
behavior and keep the configuration next to the code.
332+
Even if annotations are not natively supported by PHP, you can use them
333+
in Symfony2 as a convenient way to configure the framework behavior and
334+
keep the configuration next to the code.
361335

362336
If you take a closer look at the controller code, you can see that instead of
363337
rendering a template and returning a ``Response`` object like before, it
@@ -370,15 +344,14 @@ template is rendered (located at ``src/Acme/DemoBundle/Resources/views/Demo/hell
370344
.. tip::
371345

372346
The ``@Route()`` and ``@Template()`` annotations are more powerful than
373-
the simple examples shown in this tutorial. Learn more about "`annotations
374-
in controllers`_" in the official documentation.
347+
the simple examples shown in this tutorial. Learn more about "`annotations in controllers`_"
348+
in the official documentation.
375349

376350
Templates
377351
~~~~~~~~~
378352

379-
The controller renders the
380-
``src/Acme/DemoBundle/Resources/views/Demo/hello.html.twig`` template (or
381-
``AcmeDemoBundle:Demo:hello.html.twig`` if you use the logical name):
353+
The controller renders the ``src/Acme/DemoBundle/Resources/views/Demo/hello.html.twig``
354+
template (or ``AcmeDemoBundle:Demo:hello.html.twig`` if you use the logical name):
382355

383356
.. code-block:: jinja
384357
@@ -398,13 +371,13 @@ templates work in Symfony2.
398371
Bundles
399372
~~~~~~~
400373

401-
You might have wondered why the :term:`bundle` word is used in many names you
374+
You might have wondered why the :term:`Bundle` word is used in many names you
402375
have seen so far. All the code you write for your application is organized in
403376
bundles. In Symfony2 speak, a bundle is a structured set of files (PHP files,
404377
stylesheets, JavaScripts, images, ...) that implements a single feature (a
405378
blog, a forum, ...) and which can be easily shared with other developers. As
406379
of now, you have manipulated one bundle, AcmeDemoBundle. You will learn
407-
more about bundles in the last chapter of this tutorial.
380+
more about bundles in the :doc:`last chapter of this tutorial</quick_tour/the_architecture>`.
408381

409382
.. _quick-tour-big-picture-environments:
410383

@@ -414,12 +387,12 @@ Working with Environments
414387
Now that you have a better understanding of how Symfony2 works, take a closer
415388
look at the bottom of any Symfony2 rendered page. You should notice a small
416389
bar with the Symfony2 logo. This is the "Web Debug Toolbar", and it is a
417-
Symfony2 developer's best friend.
390+
Symfony2 developer's best friend!
418391

419392
.. image:: /images/quick_tour/web_debug_toolbar.png
420393
:align: center
421394

422-
What you see initially is only the tip of the iceberg; click on the
395+
But what you see initially is only the tip of the iceberg; click on the
423396
hexadecimal number (the session token) to reveal yet another very useful
424397
Symfony2 debugging tool: the profiler.
425398

@@ -432,21 +405,23 @@ Symfony2 debugging tool: the profiler.
432405
on the Web Debug Toolbar, or clicking them to go to their respective
433406
pages in the profiler.
434407

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.
408+
When loaded and enabled (by default in the ``dev`` :ref:`environment<quick-tour-big-picture-environments-intro>`),
409+
the Profiler provides a web interface for a *huge* amount of information recorded
410+
on each request, including logs, a timeline of the request, GET or POST parameters,
411+
security details, database queries and more!
442412

443413
Of course, it would be unwise to have these tools enabled when you deploy
444414
your application, so by default, the profiler is not enabled in the ``prod``
445-
environment. (In fact, its bundle is not even loaded).
415+
environment.
416+
417+
.. _quick-tour-big-picture-environments-intro:
446418

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:
419+
So what *is* an environment? An :term:`Environment` is a simple string (e.g.
420+
``dev`` or ``prod``) that represents a group of configuration that's used
421+
to run your application.
422+
423+
Typically, you put your common configuration in ``config.yml`` and override
424+
where necessary in the configuration for each environment. For example:
450425

451426
.. code-block:: yaml
452427
@@ -462,13 +437,12 @@ In this example, the ``dev`` environment loads the ``config_dev.yml`` configurat
462437
file, which itself imports the global ``config.yml`` file and then modifies it by
463438
enabling the web debug toolbar.
464439

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:
440+
When you visit the ``app_dev.php`` file in your browser, you're executing
441+
your Symfony application in the ``dev`` environment. To visit your application
442+
in the ``prod`` environment, visit the ``app.php`` file instead. The demo
443+
routes in our application are only available in the ``dev`` environment, but
444+
if those routes were available in the ``prod`` environment, you would be able
445+
to visit them in the ``prod`` environment by going to:
472446

473447
.. code-block:: text
474448
@@ -479,27 +453,19 @@ enabled and take advantage of the ``.htaccess`` file Symfony2 provides
479453
in ``web/``, you can even omit the ``app.php`` part of the URL. The default
480454
``.htaccess`` points all requests to the ``app.php`` front controller:
481455

482-
.. code-block:: text
483-
484-
http://localhost/demo/hello/Fabien
485-
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
488-
even better looking URL:
489-
490456
.. code-block:: text
491457
492458
http://localhost/demo/hello/Fabien
493459
494460
.. note::
495461

496-
Note that the three URLs above are provided here only as **examples** of
497-
how a URL looks like when the production front controller is used (with or
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*.
462+
Note that the two URLs above are provided here only as **examples** of
463+
how a URL looks like when the ``prod`` front controller is used. If you
464+
actually try them in an out-of-the-box installation of *Symfony Standard Edition*,
465+
you will get a 404 error since the *AcmeDemoBundle* is enabled only in
466+
the ``dev`` environment and its routes imported from ``app/config/routing_dev.yml``.
502467

468+
For more details on environments, see ":ref:`Environments & Front Controllers<page-creation-environments>`".
503469

504470
Final Thoughts
505471
--------------
@@ -512,8 +478,8 @@ are eager to learn more about Symfony2, dive into the next section:
512478

513479
.. _Symfony2 Standard Edition: http://symfony.com/download
514480
.. _Symfony in 5 minutes: http://symfony.com/symfony-in-five-minutes
481+
.. _`Composer`: http://getcomposer.org/
515482
.. _Separation of Concerns: http://en.wikipedia.org/wiki/Separation_of_concerns
516-
.. _YAML: http://www.yaml.org/
517483
.. _annotations in controllers: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html#annotations-for-controllers
518484
.. _Twig: http://twig.sensiolabs.org/
519485
.. _`Symfony Installation Page`: http://symfony.com/download

0 commit comments

Comments
 (0)