Skip to content

Commit 9d4a138

Browse files
committed
Merge branch 'master' into eom-2-2
Conflicts: book/security.rst components/property_access/introduction.rst components/stopwatch.rst cookbook/templating/namespaced_paths.rst reference/twig_reference.rst
2 parents 10fe8a4 + 821a1b4 commit 9d4a138

File tree

267 files changed

+4128
-2038
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

267 files changed

+4128
-2038
lines changed

book/controller.rst

100755100644
+17-14
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ example:
236236
237237
# app/config/routing.yml
238238
hello:
239-
path: /hello/{first_name}/{last_name}
239+
path: /hello/{firstName}/{lastName}
240240
defaults: { _controller: AcmeHelloBundle:Hello:index, color: green }
241241
242242
.. code-block:: xml
@@ -248,7 +248,7 @@ example:
248248
xsi:schemaLocation="http://symfony.com/schema/routing
249249
http://symfony.com/schema/routing/routing-1.0.xsd">
250250
251-
<route id="hello" path="/hello/{first_name}/{last_name}">
251+
<route id="hello" path="/hello/{firstName}/{lastName}">
252252
<default key="_controller">AcmeHelloBundle:Hello:index</default>
253253
<default key="color">green</default>
254254
</route>
@@ -257,19 +257,19 @@ example:
257257
.. code-block:: php
258258
259259
// app/config/routing.php
260-
$collection->add('hello', new Route('/hello/{first_name}/{last_name}', array(
260+
$collection->add('hello', new Route('/hello/{firstName}/{lastName}', array(
261261
'_controller' => 'AcmeHelloBundle:Hello:index',
262262
'color' => 'green',
263263
)));
264264
265265
The controller for this can take several arguments::
266266

267-
public function indexAction($first_name, $last_name, $color)
267+
public function indexAction($firstName, $lastName, $color)
268268
{
269269
// ...
270270
}
271271

272-
Notice that both placeholder variables (``{first_name}``, ``{last_name}``)
272+
Notice that both placeholder variables (``{firstName}``, ``{lastName}``)
273273
as well as the default ``color`` variable are available as arguments in the
274274
controller. When a route is matched, the placeholder variables are merged
275275
with the ``defaults`` to make one array that's available to your controller.
@@ -281,11 +281,11 @@ the following guidelines in mind while you develop.
281281

282282
Symfony is able to match the parameter names from the route to the variable
283283
names in the controller method's signature. In other words, it realizes that
284-
the ``{last_name}`` parameter matches up with the ``$last_name`` argument.
284+
the ``{lastName}`` parameter matches up with the ``$lastName`` argument.
285285
The arguments of the controller could be totally reordered and still work
286286
perfectly::
287287

288-
public function indexAction($last_name, $color, $first_name)
288+
public function indexAction($lastName, $color, $firstName)
289289
{
290290
// ...
291291
}
@@ -295,25 +295,25 @@ the following guidelines in mind while you develop.
295295
The following would throw a ``RuntimeException`` because there is no ``foo``
296296
parameter defined in the route::
297297

298-
public function indexAction($first_name, $last_name, $color, $foo)
298+
public function indexAction($firstName, $lastName, $color, $foo)
299299
{
300300
// ...
301301
}
302302

303303
Making the argument optional, however, is perfectly ok. The following
304304
example would not throw an exception::
305305

306-
public function indexAction($first_name, $last_name, $color, $foo = 'bar')
306+
public function indexAction($firstName, $lastName, $color, $foo = 'bar')
307307
{
308308
// ...
309309
}
310310

311311
* **Not all routing parameters need to be arguments on your controller**
312312

313-
If, for example, the ``last_name`` weren't important for your controller,
313+
If, for example, the ``lastName`` weren't important for your controller,
314314
you could omit it entirely::
315315

316-
public function indexAction($first_name, $color)
316+
public function indexAction($firstName, $color)
317317
{
318318
// ...
319319
}
@@ -501,9 +501,9 @@ value to each variable.
501501
directly by duplicating the current request. When this
502502
:ref:`sub request <http-kernel-sub-requests>` is executed via the ``http_kernel``
503503
service the ``HttpKernel`` returns a ``Response`` object::
504-
504+
505505
use Symfony\Component\HttpKernel\HttpKernelInterface;
506-
506+
507507
$path = array(
508508
'_controller' => 'AcmeHelloBundle:Hello:fancy',
509509
'name' => $name,
@@ -750,12 +750,15 @@ headers and content that's sent back to the client::
750750
use Symfony\Component\HttpFoundation\Response;
751751

752752
// create a simple Response with a 200 status code (the default)
753-
$response = new Response('Hello '.$name, 200);
753+
$response = new Response('Hello '.$name, Response::HTTP_OK);
754754

755755
// create a JSON-response with a 200 status code
756756
$response = new Response(json_encode(array('name' => $name)));
757757
$response->headers->set('Content-Type', 'application/json');
758758

759+
.. versionadded:: 2.4
760+
Support for HTTP status code constants was added in Symfony 2.4.
761+
759762
.. tip::
760763

761764
The ``headers`` property is a

book/doctrine.rst

+12-5
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ in a way that makes sense for your needs. The fact that the data needs to
10871087
be persisted to a database is always secondary.
10881088

10891089
Now, look at the metadata above the ``$category`` property on the ``Product``
1090-
class. The information here tells doctrine that the related class is ``Category``
1090+
class. The information here tells Doctrine that the related class is ``Category``
10911091
and that it should store the ``id`` of the category record on a ``category_id``
10921092
field that lives on the ``product`` table. In other words, the related ``Category``
10931093
object will be stored on the ``$category`` property, but behind the scenes,
@@ -1285,7 +1285,7 @@ More Information on Associations
12851285

12861286
This section has been an introduction to one common type of entity relationship,
12871287
the one-to-many relationship. For more advanced details and examples of how
1288-
to use other types of relations (e.g. ``one-to-one``, ``many-to-many``), see
1288+
to use other types of relations (e.g. one-to-one, many-to-many), see
12891289
Doctrine's `Association Mapping Documentation`_.
12901290

12911291
.. note::
@@ -1441,12 +1441,19 @@ using. The following types are supported in Doctrine:
14411441
* ``date``
14421442
* ``time``
14431443
* ``datetime``
1444+
* ``datetimetz``
14441445

14451446
* **Other Types**
14461447

14471448
* ``boolean``
14481449
* ``object`` (serialized and stored in a ``CLOB`` field)
14491450
* ``array`` (serialized and stored in a ``CLOB`` field)
1451+
* ``blob`` (mapped to a resource stream)
1452+
* ``simple_array`` (serialized using :phpfunction:`implode()` and :phpfunction:`explode()`,
1453+
with a comma as delimiter, and stored in a ``CLOB`` field)
1454+
* ``json_array`` (serialized using :phpfunction:`json_encode()` and :phpfunction:`json_decode()`,
1455+
and stored in a ``CLOB`` field)
1456+
* ``guid``
14501457

14511458
For more information, see Doctrine's `Mapping Types documentation`_.
14521459

@@ -1483,7 +1490,7 @@ and ``nullable``. Take a few examples:
14831490
fields:
14841491
# A string field length 255 that cannot be null
14851492
# (reflecting the default values for the "length" and *nullable* options)
1486-
# type attribute is necessary in yaml definitions
1493+
# type attribute is necessary in YAML definitions
14871494
name:
14881495
type: string
14891496
@@ -1500,7 +1507,7 @@ and ``nullable``. Take a few examples:
15001507
<!--
15011508
A string field length 255 that cannot be null
15021509
(reflecting the default values for the "length" and *nullable* options)
1503-
type attribute is necessary in xml definitions
1510+
type attribute is necessary in XML definitions
15041511
-->
15051512
<field name="name" type="string" />
15061513
<field name="email"
@@ -1562,7 +1569,7 @@ Some notable or interesting tasks include:
15621569
.. note::
15631570

15641571
To be able to load data fixtures to your database, you will need to have
1565-
the ``DoctrineFixturesBundle`` bundle installed. To learn how to do it,
1572+
the DoctrineFixturesBundle bundle installed. To learn how to do it,
15661573
read the ":doc:`/bundles/DoctrineFixturesBundle/index`" entry of the
15671574
documentation.
15681575

book/forms.rst

+32-12
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ learning the most important features of the form library along the way.
1111

1212
.. note::
1313

14-
The Symfony form component is a standalone library that can be used outside
15-
of Symfony2 projects. For more information, see the `Symfony2 Form Component`_
14+
The Symfony Form component is a standalone library that can be used outside
15+
of Symfony2 projects. For more information, see the `Symfony2 Form component`_
1616
on Github.
1717

1818
.. index::
@@ -186,7 +186,7 @@ it into a format that's suitable for being rendered in an HTML form.
186186
The form system is smart enough to access the value of the protected
187187
``task`` property via the ``getTask()`` and ``setTask()`` methods on the
188188
``Task`` class. Unless a property is public, it *must* have a "getter" and
189-
"setter" method so that the form component can get and put data onto the
189+
"setter" method so that the Form component can get and put data onto the
190190
property. For a Boolean property, you can use an "isser" or "hasser" method
191191
(e.g. ``isPublished()`` or ``hasReminder()``) instead of a getter (e.g.
192192
``getPublished()`` or ``getReminder()``).
@@ -420,6 +420,22 @@ corresponding errors printed out with the form.
420420
but are being prevented by your browser from, for example, submitting
421421
blank fields.
422422

423+
.. configuration-block::
424+
425+
.. code-block:: html+jinja
426+
427+
{# src/Acme/DemoBundle/Resources/views/Default/new.html.twig #}
428+
429+
{{ form(form, {'attr': {'novalidate': 'novalidate'}}) }}
430+
431+
.. code-block:: html+php
432+
433+
<!-- src/Acme/DemoBundle/Resources/views/Default/new.html.php -->
434+
435+
<?php echo $view['form']->form($form, array(
436+
'attr' => array('novalidate' => 'novalidate'),
437+
)) ?>
438+
423439
Validation is a very powerful feature of Symfony2 and has its own
424440
:doc:`dedicated chapter </book/validation>`.
425441

@@ -806,7 +822,9 @@ used the ``form_row`` helper:
806822
{{ form_widget(form.dueDate) }}
807823
</div>
808824

809-
<input type="submit" />
825+
<div>
826+
{{ form_widget(form.save) }}
827+
</div>
810828

811829
{{ form_end(form) }}
812830

@@ -828,7 +846,9 @@ used the ``form_row`` helper:
828846
<?php echo $view['form']->widget($form['dueDate']) ?>
829847
</div>
830848

831-
<input type="submit" />
849+
<div>
850+
<?php echo $view['form']->widget($form['save']) ?>
851+
</div>
832852

833853
<?php echo $view['form']->end($form) ?>
834854

@@ -1193,7 +1213,7 @@ Embedded Forms
11931213
Often, you'll want to build a form that will include fields from many different
11941214
objects. For example, a registration form may contain data belonging to
11951215
a ``User`` object as well as many ``Address`` objects. Fortunately, this
1196-
is easy and natural with the form component.
1216+
is easy and natural with the Form component.
11971217
11981218
Embedding a Single Object
11991219
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1395,7 +1415,7 @@ do this, create a new template file that will store the new markup:
13951415
</div>
13961416
13971417
The ``form_row`` form fragment is used when rendering most fields via the
1398-
``form_row`` function. To tell the form component to use your new ``form_row``
1418+
``form_row`` function. To tell the Form component to use your new ``form_row``
13991419
fragment defined above, add the following to the top of the template that
14001420
renders the form:
14011421
@@ -1408,7 +1428,7 @@ renders the form:
14081428
14091429
{% form_theme form 'AcmeTaskBundle:Form:fields.html.twig' 'AcmeTaskBundle:Form:fields2.html.twig' %}
14101430
1411-
{{ form(form) }}
1431+
<!-- ... render the form -->
14121432
14131433
.. code-block:: html+php
14141434
@@ -1417,7 +1437,7 @@ renders the form:
14171437
14181438
<?php $view['form']->setTheme($form, array('AcmeTaskBundle:Form', 'AcmeTaskBundle:Form')) ?>
14191439
1420-
<?php echo $view['form']->form($form) ?>
1440+
<!-- ... render the form -->
14211441
14221442
The ``form_theme`` tag (in Twig) "imports" the fragments defined in the given
14231443
template and uses them when rendering the form. In other words, when the
@@ -1455,7 +1475,7 @@ Form Fragment Naming
14551475
~~~~~~~~~~~~~~~~~~~~
14561476
14571477
In Symfony, every part of a form that is rendered - HTML form elements, errors,
1458-
labels, etc - is defined in a base theme, which is a collection of blocks
1478+
labels, etc. - is defined in a base theme, which is a collection of blocks
14591479
in Twig and a collection of template files in PHP.
14601480
14611481
In Twig, every block needed is defined in a single template file (`form_div_layout.html.twig`_)
@@ -1856,7 +1876,7 @@ There's still much more to learn about the powerful world of forms, such as
18561876
how to handle
18571877
:doc:`file uploads with Doctrine </cookbook/doctrine/file_uploads>` or how
18581878
to create a form where a dynamic number of sub-forms can be added (e.g. a
1859-
todo list where you can keep adding more fields via Javascript before submitting).
1879+
todo list where you can keep adding more fields via JavaScript before submitting).
18601880
See the cookbook for these topics. Also, be sure to lean on the
18611881
:doc:`field type reference documentation </reference/forms/types>`, which
18621882
includes examples of how to use each field type and its options.
@@ -1871,7 +1891,7 @@ Learn more from the Cookbook
18711891
* :doc:`/cookbook/form/dynamic_form_modification`
18721892
* :doc:`/cookbook/form/data_transformers`
18731893
1874-
.. _`Symfony2 Form Component`: https://github.com/symfony/Form
1894+
.. _`Symfony2 Form component`: https://github.com/symfony/Form
18751895
.. _`DateTime`: http://php.net/manual/en/class.datetime.php
18761896
.. _`Twig Bridge`: https://github.com/symfony/symfony/tree/master/src/Symfony/Bridge/Twig
18771897
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

book/from_flat_php_to_symfony2.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ the layout:
247247
You've now introduced a methodology that allows for the reuse of the
248248
layout. Unfortunately, to accomplish this, you're forced to use a few ugly
249249
PHP functions (``ob_start()``, ``ob_get_clean()``) in the template. Symfony2
250-
uses a ``Templating`` component that allows this to be accomplished cleanly
250+
uses a Templating component that allows this to be accomplished cleanly
251251
and easily. You'll see it in action shortly.
252252

253253
Adding a Blog "show" Page
@@ -476,12 +476,15 @@ the HTTP response being returned. Use them to improve the blog:
476476
$response = show_action($request->query->get('id'));
477477
} else {
478478
$html = '<html><body><h1>Page Not Found</h1></body></html>';
479-
$response = new Response($html, 404);
479+
$response = new Response($html, Response::HTTP_NOT_FOUND);
480480
}
481481

482482
// echo the headers and send the response
483483
$response->send();
484484

485+
.. versionadded:: 2.4
486+
Support for HTTP status code constants was added in Symfony 2.4.
487+
485488
The controllers are now responsible for returning a ``Response`` object.
486489
To make this easier, you can add a new ``render_template()`` function, which,
487490
incidentally, acts quite a bit like the Symfony2 templating engine:
@@ -583,7 +586,7 @@ them for you. Here's the same sample application, now built in Symfony2::
583586
}
584587

585588
The two controllers are still lightweight. Each uses the :doc:`Doctrine ORM library </book/doctrine>`
586-
to retrieve objects from the database and the ``Templating`` component to
589+
to retrieve objects from the database and the Templating component to
587590
render a template and return a ``Response`` object. The list template is
588591
now quite a bit simpler:
589592

@@ -688,7 +691,7 @@ migrating the blog from flat PHP to Symfony2 has improved life:
688691
Templating, Security, Form, Validation and Translation components (to name
689692
a few);
690693

691-
* The application now enjoys **fully-flexible URLs** thanks to the ``Routing``
694+
* The application now enjoys **fully-flexible URLs** thanks to the Routing
692695
component;
693696

694697
* Symfony2's HTTP-centric architecture gives you access to powerful tools

book/http_cache.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ The resulting HTTP header will look like this:
474474

475475
Note that in HTTP versions before 1.1 the origin server wasn't required to
476476
send the ``Date`` header. Consequently the cache (e.g. the browser) might
477-
need to rely onto his local clock to evaluate the ``Expires`` header making
477+
need to rely on the local clock to evaluate the ``Expires`` header making
478478
the lifetime calculation vulnerable to clock skew. Another limitation
479479
of the ``Expires`` header is that the specification states that "HTTP/1.1
480480
servers should not send ``Expires`` dates more than one year in the future."
@@ -535,7 +535,7 @@ example).
535535
The 304 status code means "Not Modified". It's important because with
536536
this status code the response does *not* contain the actual content being
537537
requested. Instead, the response is simply a light-weight set of directions that
538-
tell cache that it should use its stored version.
538+
tells the cache that it should use its stored version.
539539

540540
Like with expiration, there are two different HTTP headers that can be used
541541
to implement the validation model: ``ETag`` and ``Last-Modified``.
@@ -1059,15 +1059,18 @@ Here is how you can configure the Symfony2 reverse proxy to support the
10591059

10601060
$response = new Response();
10611061
if (!$this->getStore()->purge($request->getUri())) {
1062-
$response->setStatusCode(404, 'Not purged');
1062+
$response->setStatusCode(Response::HTTP_NOT_FOUND, 'Not purged');
10631063
} else {
1064-
$response->setStatusCode(200, 'Purged');
1064+
$response->setStatusCode(Response::HTTP_OK, 'Purged');
10651065
}
10661066

10671067
return $response;
10681068
}
10691069
}
10701070

1071+
.. versionadded:: 2.4
1072+
Support for HTTP status code constants was added in Symfony 2.4.
1073+
10711074
.. caution::
10721075

10731076
You must protect the ``PURGE`` HTTP method somehow to avoid random people

0 commit comments

Comments
 (0)