@@ -21,28 +21,17 @@ Apache) with PHP 5.3.3 or higher.
21
21
22
22
.. tip ::
23
23
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> ` .
27
27
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
41
29
:term: `distribution ` that is preconfigured for the most common use cases and
42
30
also contains some code that demonstrates how to use Symfony2 (get the archive
43
31
with the *vendors * included to get started even faster).
44
32
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
46
35
have a ``Symfony/ `` directory that looks like this:
47
36
48
37
.. code-block :: text
@@ -71,35 +60,40 @@ have a ``Symfony/`` directory that looks like this:
71
60
72
61
.. note ::
73
62
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 ``):
76
66
77
67
.. code-block :: bash
78
68
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
80
70
81
- # remove the Git history
82
- $ rm -rf .git
71
+ .. _`quick-tour-big-picture-built-in-server` :
83
72
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:
86
74
87
- .. tip ::
75
+ .. code-block :: bash
88
76
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
90
79
91
- .. code-block :: bash
80
+ # run the built-in web server
81
+ $ php php app/console server:run
92
82
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"
95
84
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.
98
87
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".
100
92
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.
103
97
104
98
Checking the Configuration
105
99
--------------------------
@@ -114,31 +108,13 @@ URL to see the diagnostics for your machine:
114
108
115
109
.. note ::
116
110
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.
142
118
143
119
If there are any outstanding issues listed, correct them. You might also tweak
144
120
your configuration by following any given recommendations. When everything is
@@ -196,8 +172,8 @@ Routing
196
172
~~~~~~~
197
173
198
174
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
201
177
file. When you're in the ``dev `` :ref: `environment<quick-tour-big-picture-environments> ` -
202
178
indicated by the app_**dev**.php front controller - the ``app/config/routing_dev.yml ``
203
179
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.
224
200
225
201
.. tip ::
226
202
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.
233
209
234
210
Controllers
235
211
~~~~~~~~~~~
236
212
237
213
A controller is a fancy name for a PHP function or method that handles incoming
238
214
*requests * and returns *responses * (often HTML code). Instead of using the
239
215
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
242
218
controller might create the response by hand, based on the request::
243
219
244
220
use Symfony\Component\HttpFoundation\Response;
@@ -281,11 +257,10 @@ the ``Acme\DemoBundle\Controller\WelcomeController`` class::
281
257
282
258
The ``WelcomeController `` class extends the built-in ``Controller `` class,
283
259
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::
289
264
290
265
public function indexAction()
291
266
{
@@ -308,10 +283,9 @@ return the contents of a JPG image with a ``Content-Type`` header of ``image/jpg
308
283
everything about Symfony2 controllers.
309
284
310
285
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.
315
289
316
290
Now, take a look at the routing configuration again and find the ``_demo ``
317
291
key:
@@ -355,9 +329,9 @@ you can see, its value can be retrieved through the ``$name`` method argument.
355
329
356
330
.. note ::
357
331
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.
361
335
362
336
If you take a closer look at the controller code, you can see that instead of
363
337
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
370
344
.. tip ::
371
345
372
346
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.
375
349
376
350
Templates
377
351
~~~~~~~~~
378
352
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):
382
355
383
356
.. code-block :: jinja
384
357
@@ -398,13 +371,13 @@ templates work in Symfony2.
398
371
Bundles
399
372
~~~~~~~
400
373
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
402
375
have seen so far. All the code you write for your application is organized in
403
376
bundles. In Symfony2 speak, a bundle is a structured set of files (PHP files,
404
377
stylesheets, JavaScripts, images, ...) that implements a single feature (a
405
378
blog, a forum, ...) and which can be easily shared with other developers. As
406
379
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> ` .
408
381
409
382
.. _quick-tour-big-picture-environments :
410
383
@@ -414,12 +387,12 @@ Working with Environments
414
387
Now that you have a better understanding of how Symfony2 works, take a closer
415
388
look at the bottom of any Symfony2 rendered page. You should notice a small
416
389
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!
418
391
419
392
.. image :: /images/quick_tour/web_debug_toolbar.png
420
393
:align: center
421
394
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
423
396
hexadecimal number (the session token) to reveal yet another very useful
424
397
Symfony2 debugging tool: the profiler.
425
398
@@ -432,21 +405,23 @@ Symfony2 debugging tool: the profiler.
432
405
on the Web Debug Toolbar, or clicking them to go to their respective
433
406
pages in the profiler.
434
407
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!
442
412
443
413
Of course, it would be unwise to have these tools enabled when you deploy
444
414
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 :
446
418
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:
450
425
451
426
.. code-block :: yaml
452
427
@@ -462,13 +437,12 @@ In this example, the ``dev`` environment loads the ``config_dev.yml`` configurat
462
437
file, which itself imports the global ``config.yml `` file and then modifies it by
463
438
enabling the web debug toolbar.
464
439
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:
472
446
473
447
.. code-block :: text
474
448
@@ -479,27 +453,19 @@ enabled and take advantage of the ``.htaccess`` file Symfony2 provides
479
453
in ``web/ ``, you can even omit the ``app.php `` part of the URL. The default
480
454
``.htaccess `` points all requests to the ``app.php `` front controller:
481
455
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
-
490
456
.. code-block :: text
491
457
492
458
http://localhost/demo/hello/Fabien
493
459
494
460
.. note ::
495
461
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 ``.
502
467
468
+ For more details on environments, see ":ref: `Environments & Front Controllers<page-creation-environments> `".
503
469
504
470
Final Thoughts
505
471
--------------
@@ -512,8 +478,8 @@ are eager to learn more about Symfony2, dive into the next section:
512
478
513
479
.. _Symfony2 Standard Edition : http://symfony.com/download
514
480
.. _Symfony in 5 minutes : http://symfony.com/symfony-in-five-minutes
481
+ .. _`Composer` : http://getcomposer.org/
515
482
.. _Separation of Concerns : http://en.wikipedia.org/wiki/Separation_of_concerns
516
- .. _YAML : http://www.yaml.org/
517
483
.. _annotations in controllers : http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html#annotations-for-controllers
518
484
.. _Twig : http://twig.sensiolabs.org/
519
485
.. _`Symfony Installation Page` : http://symfony.com/download
0 commit comments