Skip to content

Commit 46167a6

Browse files
committed
Merge branch '2.3' into 2.5
* 2.3: [#4336] Backporting minor syntax fix Included a bunch of fixes suggested by the awesome Symfony doc reviewers Added a bunch of fixes suggested by @xabbuh Fixed a RST formatting issue Revamped the Quick Start tutorial tweaks to #4427 Updated first code-block:: bash Conflicts: quick_tour/the_big_picture.rst
2 parents 7cc4287 + 0380d34 commit 46167a6

File tree

8 files changed

+592
-537
lines changed

8 files changed

+592
-537
lines changed

Diff for: book/routing.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ entries? Update the route to have a new ``{page}`` placeholder:
406406
.. code-block:: php-annotations
407407
408408
// src/AppBundle/Controller/BlogController.php
409-
409+
410410
// ...
411411
412412
/**
@@ -466,7 +466,7 @@ This is done by including it in the ``defaults`` collection:
466466
.. code-block:: php-annotations
467467
468468
// src/AppBundle/Controller/BlogController.php
469-
469+
470470
// ...
471471
472472
/**
@@ -551,7 +551,7 @@ Take a quick look at the routes that have been created so far:
551551
.. code-block:: php-annotations
552552
553553
// src/AppBundle/Controller/BlogController.php
554-
554+
555555
// ...
556556
class BlogController extends Controller
557557
{
@@ -735,7 +735,7 @@ URL:
735735
.. code-block:: php-annotations
736736
737737
// src/AppBundle/Controller/MainController.php
738-
738+
739739
// ...
740740
class MainController extends Controller
741741
{
@@ -1360,8 +1360,8 @@ suppose you want to prefix all routes in the AppBundle with ``/site`` (e.g.
13601360
13611361
return $collection;
13621362
1363-
The string ``/site`` will now be prepended to the path of each route loaded
1364-
from the new routing resource.
1363+
The path of each route being loaded from the new routing resource will now
1364+
be prefixed with the string ``/site``.
13651365

13661366
Adding a Host Requirement to Imported Routes
13671367
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Diff for: book/templating.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ By default, templates can live in two different locations:
382382
third party bundle templates (see :ref:`overriding-bundle-templates`);
383383

384384
* ``path/to/bundle/Resources/views/``: Each third party bundle houses its
385-
templates in its ``Resources/views`` directory (and subdirectories). When you
385+
templates in its ``Resources/views/`` directory (and subdirectories). When you
386386
plan to share your bundle, you should put the templates in the bundle instead
387387
of the ``app/`` directory.
388388

@@ -430,8 +430,8 @@ directory. This gives the power to override templates from any vendor bundle.
430430

431431
.. tip::
432432

433-
Hopefully the template naming syntax looks familiar - it's similair to the
434-
naming convention used to refer to :ref:`controller-string-syntax`.
433+
Hopefully the template naming syntax looks familiar - it's similar to
434+
the naming convention used to refer to :ref:`controller-string-syntax`.
435435

436436
Template Suffix
437437
~~~~~~~~~~~~~~~
@@ -1376,7 +1376,7 @@ covered:
13761376
{% endblock %}
13771377

13781378
Notice that this template extends the section template (``Blog/layout.html.twig``)
1379-
which in-turn extends the base application layout (``base.html.twig``). This is
1379+
which in turn extends the base application layout (``base.html.twig``). This is
13801380
the common three-level inheritance model.
13811381

13821382
When building your application, you may choose to follow this method or simply
@@ -1489,7 +1489,7 @@ Debugging
14891489

14901490
When using PHP, you can use :phpfunction:`var_dump` if you need to quickly find
14911491
the value of a variable passed. This is useful, for example, inside your
1492-
controller. The same can be achieved when using Twig thanks to the debug
1492+
controller. The same can be achieved when using Twig thanks to the Debug
14931493
extension.
14941494

14951495
Template parameters can then be dumped using the ``dump`` function:

Diff for: cookbook/console/console_command.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ This command will now automatically be available to run:
5959

6060
.. code-block:: bash
6161
62-
$ app/console demo:greet Fabien
62+
$ php app/console demo:greet Fabien
6363
6464
.. _cookbook-console-dic:
6565

Diff for: quick_tour/the_architecture.rst

+59-91
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ Understanding the Directory Structure
1313
The directory structure of a Symfony :term:`application` is rather flexible,
1414
but the recommended structure is as follows:
1515

16-
* ``app/``: the application configuration;
17-
* ``src/``: the project's PHP code;
16+
* ``app/``: the application configuration, templates and translations;
17+
* ``src/``: the project's PHP code;
1818
* ``vendor/``: the third-party dependencies;
19-
* ``web/``: the web root directory.
19+
* ``web/``: the web root directory.
2020

2121
The ``web/`` Directory
2222
~~~~~~~~~~~~~~~~~~~~~~
2323

2424
The web root directory is the home of all public and static files like images,
2525
stylesheets, and JavaScript files. It is also where each :term:`front controller`
26-
lives::
26+
lives, such as the production controller shown here::
2727

2828
// web/app.php
2929
require_once __DIR__.'/../app/bootstrap.php.cache';
@@ -33,7 +33,9 @@ lives::
3333

3434
$kernel = new AppKernel('prod', false);
3535
$kernel->loadClassCache();
36-
$kernel->handle(Request::createFromGlobals())->send();
36+
$request = Request::createFromGlobals();
37+
$response = $kernel->handle($request);
38+
$response->send();
3739

3840
The controller first bootstraps the application using a kernel class (``AppKernel``
3941
in this case). Then, it creates the ``Request`` object using the PHP's global
@@ -51,8 +53,7 @@ configuration and as such, it is stored in the ``app/`` directory.
5153
This class must implement two methods:
5254

5355
* ``registerBundles()`` must return an array of all bundles needed to run the
54-
application;
55-
56+
application, as explained in the next section;
5657
* ``registerContainerConfiguration()`` loads the application configuration
5758
(more on this later).
5859

@@ -73,12 +74,21 @@ A bundle is kind of like a plugin in other software. So why is it called a
7374
Symfony, from the core framework features to the code you write for your
7475
application.
7576

77+
All the code you write for your application is organized in bundles. In Symfony
78+
speak, a bundle is a structured set of files (PHP files, stylesheets, JavaScripts,
79+
images, ...) that implements a single feature (a blog, a forum, ...) and which
80+
can be easily shared with other developers.
81+
7682
Bundles are first-class citizens in Symfony. This gives you the flexibility
7783
to use pre-built features packaged in third-party bundles or to distribute your
7884
own bundles. It makes it easy to pick and choose which features to enable in
7985
your application and optimize them the way you want. And at the end of the day,
8086
your application code is just as *important* as the core framework itself.
8187

88+
Symfony already includes an ``AppBundle`` that you may use to start developing
89+
your application. Then, if you need to split the application into reusable
90+
components, you can create your own bundles.
91+
8292
Registering a Bundle
8393
~~~~~~~~~~~~~~~~~~~~
8494

@@ -98,10 +108,10 @@ a single ``Bundle`` class that describes it::
98108
new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
99109
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
100110
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
111+
new AppBundle\AppBundle();
101112
);
102113

103114
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
104-
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
105115
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
106116
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
107117
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
@@ -110,23 +120,23 @@ a single ``Bundle`` class that describes it::
110120
return $bundles;
111121
}
112122

113-
In addition to the AcmeDemoBundle that was already talked about, notice
114-
that the kernel also enables other bundles such as the FrameworkBundle,
115-
DoctrineBundle, SwiftmailerBundle and AsseticBundle bundle. They are all part
116-
of the core framework.
123+
In addition to the AppBundle that was already talked about, notice that the
124+
kernel also enables other bundles that are part of Symfony, such as FrameworkBundle,
125+
DoctrineBundle, SwiftmailerBundle and AsseticBundle.
117126

118127
Configuring a Bundle
119128
~~~~~~~~~~~~~~~~~~~~
120129

121130
Each bundle can be customized via configuration files written in YAML, XML, or
122-
PHP. Have a look at the default Symfony configuration:
131+
PHP. Have a look at this sample of the default Symfony configuration:
123132

124133
.. code-block:: yaml
125134
126135
# app/config/config.yml
127136
imports:
128137
- { resource: parameters.yml }
129138
- { resource: security.yml }
139+
- { resource: services.yml }
130140
131141
framework:
132142
#esi: ~
@@ -138,7 +148,7 @@ PHP. Have a look at the default Symfony configuration:
138148
form: true
139149
csrf_protection: true
140150
validation: { enable_annotations: true }
141-
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
151+
templating: { engines: ['twig'] }
142152
default_locale: "%locale%"
143153
trusted_proxies: ~
144154
session: ~
@@ -148,34 +158,6 @@ PHP. Have a look at the default Symfony configuration:
148158
debug: "%kernel.debug%"
149159
strict_variables: "%kernel.debug%"
150160
151-
# Assetic Configuration
152-
assetic:
153-
debug: "%kernel.debug%"
154-
use_controller: false
155-
bundles: [ ]
156-
#java: /usr/bin/java
157-
filters:
158-
cssrewrite: ~
159-
#closure:
160-
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
161-
#yui_css:
162-
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
163-
164-
# Doctrine Configuration
165-
doctrine:
166-
dbal:
167-
driver: "%database_driver%"
168-
host: "%database_host%"
169-
port: "%database_port%"
170-
dbname: "%database_name%"
171-
user: "%database_user%"
172-
password: "%database_password%"
173-
charset: UTF8
174-
175-
orm:
176-
auto_generate_proxy_classes: "%kernel.debug%"
177-
auto_mapping: true
178-
179161
# Swift Mailer Configuration
180162
swiftmailer:
181163
transport: "%mailer_transport%"
@@ -184,9 +166,11 @@ PHP. Have a look at the default Symfony configuration:
184166
password: "%mailer_password%"
185167
spool: { type: memory }
186168
187-
Each first level entry like ``framework``, ``twig`` or ``doctrine`` defines the
188-
configuration for a specific bundle. For example, ``framework`` configures the
189-
FrameworkBundle while ``swiftmailer`` configures the SwiftmailerBundle.
169+
# ...
170+
171+
Each first level entry like ``framework``, ``twig`` and ``swiftmailer`` defines
172+
the configuration for a specific bundle. For example, ``framework`` configures
173+
the FrameworkBundle while ``swiftmailer`` configures the SwiftmailerBundle.
190174

191175
Each :term:`environment` can override the default configuration by providing a
192176
specific configuration file. For example, the ``dev`` environment loads the
@@ -207,64 +191,42 @@ and then modifies it to add some debugging tools:
207191
toolbar: true
208192
intercept_redirects: false
209193
210-
monolog:
211-
handlers:
212-
main:
213-
type: stream
214-
path: "%kernel.logs_dir%/%kernel.environment%.log"
215-
level: debug
216-
firephp:
217-
type: firephp
218-
level: info
219-
220-
assetic:
221-
use_controller: true
194+
# ...
222195
223196
Extending a Bundle
224197
~~~~~~~~~~~~~~~~~~
225198

226199
In addition to being a nice way to organize and configure your code, a bundle
227200
can extend another bundle. Bundle inheritance allows you to override any existing
228201
bundle in order to customize its controllers, templates, or any of its files.
229-
This is where the logical names (e.g. ``@AcmeDemoBundle/Controller/SecuredController.php``)
230-
come in handy: they abstract where the resource is actually stored.
231202

232203
Logical File Names
233204
..................
234205

235206
When you want to reference a file from a bundle, use this notation:
236207
``@BUNDLE_NAME/path/to/file``; Symfony will resolve ``@BUNDLE_NAME``
237208
to the real path to the bundle. For instance, the logical path
238-
``@AcmeDemoBundle/Controller/DemoController.php`` would be converted to
239-
``src/Acme/DemoBundle/Controller/DemoController.php``, because Symfony knows
240-
the location of the AcmeDemoBundle.
209+
``@AppBundle/Controller/DefaultController.php`` would be converted to
210+
``src/AppBundle/Controller/DefaultController.php``, because Symfony knows
211+
the location of the AppBundle.
241212

242213
Logical Controller Names
243214
........................
244215

245-
For controllers, you need to reference method names using the format
216+
For controllers, you need to reference actions using the format
246217
``BUNDLE_NAME:CONTROLLER_NAME:ACTION_NAME``. For instance,
247-
``AcmeDemoBundle:Welcome:index`` maps to the ``indexAction`` method from the
248-
``Acme\DemoBundle\Controller\WelcomeController`` class.
249-
250-
Logical Template Names
251-
......................
252-
253-
For templates, the logical name ``AcmeDemoBundle:Welcome:index.html.twig`` is
254-
converted to the file path ``src/Acme/DemoBundle/Resources/views/Welcome/index.html.twig``.
255-
Templates become even more interesting when you realize they don't need to be
256-
stored on the filesystem. You can easily store them in a database table for
257-
instance.
218+
``AppBundle:Default:index`` maps to the ``indexAction`` method from the
219+
``AppBundle\Controller\DefaultController`` class.
258220

259221
Extending Bundles
260222
.................
261223

262-
If you follow these conventions, then you can use :doc:`bundle inheritance</cookbook/bundles/inheritance>`
263-
to "override" files, controllers or templates. For example, you can create
264-
a bundle - AcmeNewBundle - and specify that it overrides AcmeDemoBundle.
265-
When Symfony loads the ``AcmeDemoBundle:Welcome:index`` controller, it will
266-
first look for the ``WelcomeController`` class in AcmeNewBundle and, if
267-
it doesn't exist, then look inside AcmeDemoBundle. This means that one bundle
224+
If you follow these conventions, then you can use :doc:`bundle inheritance </cookbook/bundles/inheritance>`
225+
to override files, controllers or templates. For example, you can create
226+
a bundle - NewBundle - and specify that it overrides AppBundle.
227+
When Symfony loads the ``AppBundle:Default:index`` controller, it will
228+
first look for the ``DefaultController`` class in NewBundle and, if
229+
it doesn't exist, then look inside AppBundle. This means that one bundle
268230
can override almost any part of another bundle!
269231

270232
Do you understand now why Symfony is so flexible? Share your bundles between
@@ -276,22 +238,28 @@ Using Vendors
276238
-------------
277239

278240
Odds are that your application will depend on third-party libraries. Those
279-
should be stored in the ``vendor/`` directory. This directory already contains
280-
the Symfony libraries, the SwiftMailer library, the Doctrine ORM, the Twig
281-
templating system, and some other third party libraries and bundles.
241+
should be stored in the ``vendor/`` directory. You should never touch anything
242+
in this directory, because it is exclusively managed by Composer. This directory
243+
already contains the Symfony libraries, the SwiftMailer library, the Doctrine ORM,
244+
the Twig templating system and some other third party libraries and bundles.
282245

283246
Understanding the Cache and Logs
284247
--------------------------------
285248

286-
Symfony is probably one of the fastest full-stack frameworks around. But how
287-
can it be so fast if it parses and interprets tens of YAML and XML files for
288-
each request? The speed is partly due to its cache system. The application
249+
Symfony applications can contain tens of configuration files defined in several
250+
formats (YAML, XML, PHP, etc.) Instead of parsing and combining all those files
251+
for each request, Symfony uses its own cache system. In fact, the application
289252
configuration is only parsed for the very first request and then compiled down
290-
to plain PHP code stored in the ``app/cache/`` directory. In the development
291-
environment, Symfony is smart enough to flush the cache when you change a
292-
file. But in the production environment, to speed things up, it is your
293-
responsibility to clear the cache when you update your code or change its
294-
configuration.
253+
to plain PHP code stored in the ``app/cache/`` directory.
254+
255+
In the development environment, Symfony is smart enough to update the cache when
256+
you change a file. But in the production environment, to speed things up, it is
257+
your responsibility to clear the cache when you update your code or change its
258+
configuration. Execute this command to clear the cache in the ``prod`` environment:
259+
260+
.. code-block:: bash
261+
262+
$ php app/console cache:clear --env=prod
295263
296264
When developing a web application, things can go wrong in many ways. The log
297265
files in the ``app/logs/`` directory tell you everything about the requests

0 commit comments

Comments
 (0)