Skip to content

Commit d6ce29f

Browse files
committed
Merge branch '2.7'
* 2.7: (22 commits) Fix up the final sentence to be a bit cleaner. SetDescription required on Product entities typo fix Fixed typo Modifying the best practice to use form_start() instead of <form Proposing that we make the service names *just* a little bit longer fix elseif statement Added a reference to the Bootstrap 3 form theme remove versionadded directives for old versions Fixed wrong indentation Bot fixes refer to the VarDumper component for dump() tweaks to the Twig reference Removed unnecessary use statement in code example in the debugging cookbook [Form] document $deep and $flatten of getErrors() describe how to access form errors Changed userName to username Update slash_in_parameter.rst Applied suggestion by Ryan Update form_customization.rst ...
2 parents 51224e9 + 3ecfcaf commit d6ce29f

23 files changed

+209
-138
lines changed

best_practices/business-logic.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Next, define a new service for that class.
8181
# app/config/services.yml
8282
services:
8383
# keep your service names short
84-
slugger:
84+
app.slugger:
8585
class: AppBundle\Utils\Slugger
8686
8787
Traditionally, the naming convention for a service involved following the
@@ -92,7 +92,8 @@ your code will be easier to read and use.
9292
.. best-practice::
9393

9494
The name of your application's services should be as short as possible,
95-
ideally just one simple word.
95+
but unique enough that you can search your project for the service if
96+
you ever need to.
9697

9798
Now you can use the custom slugger in any controller class, such as the
9899
``AdminController``:
@@ -104,7 +105,7 @@ Now you can use the custom slugger in any controller class, such as the
104105
// ...
105106
106107
if ($form->isSubmitted() && $form->isValid()) {
107-
$slug = $this->get('slugger')->slugify($post->getTitle());
108+
$slug = $this->get('app.slugger')->slugify($post->getTitle());
108109
$post->setSlug($slug);
109110
110111
// ...
@@ -143,7 +144,7 @@ the class namespace as a parameter:
143144
slugger.class: AppBundle\Utils\Slugger
144145
145146
services:
146-
slugger:
147+
app.slugger:
147148
class: "%slugger.class%"
148149
149150
This practice is cumbersome and completely unnecessary for your own services:

best_practices/forms.rst

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,15 @@ There are a lot of ways to render your form, ranging from rendering the entire
157157
thing in one line to rendering each part of each field independently. The
158158
best way depends on how much customization you need.
159159

160-
The simplest way - which is especially useful during development - is to render
161-
the form tags manually and then use ``form_widget()`` to render all of the fields:
160+
One of the simplest ways - which is especially useful during development -
161+
is to render the form tags and use ``form_widget()`` to render all of the
162+
fields:
162163

163164
.. code-block:: html+jinja
164165

165-
<form method="POST" {{ form_enctype(form) }}>
166+
{{ form_start(form, {'attr': {'class': 'my-form-class'} }) }}
166167
{{ form_widget(form) }}
167-
</form>
168-
169-
.. best-practice::
170-
171-
Don't use the ``form()`` or ``form_start()`` functions to render the
172-
starting and ending form tags.
173-
174-
Experienced Symfony developers will recognize that we're rendering the ``<form>``
175-
tags manually instead of using the ``form_start()`` or ``form()`` functions.
176-
While those are convenient, they take away from some clarity with little
177-
benefit.
178-
179-
.. tip::
180-
181-
The exception is a delete form because it's really just one button and
182-
so benefits from some of these extra shortcuts.
168+
{{ form_end(form) }}
183169

184170
If you need more control over how your fields are rendered, then you should
185171
remove the ``form_widget(form)`` function and render your fields individually.

book/doctrine.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ Now you can see this new code in action! Imagine you're inside a controller::
11051105
$product = new Product();
11061106
$product->setName('Foo');
11071107
$product->setPrice(19.99);
1108+
$product->setDescription('Lorem ipsum dolor');
11081109
// relate this product to the category
11091110
$product->setCategory($category);
11101111

book/from_flat_php_to_symfony2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ on the requested URI:
367367
require_once 'controllers.php';
368368

369369
// route the request internally
370-
$uri = $_SERVER['REQUEST_URI'];
370+
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
371371
if ('/index.php' == $uri) {
372372
list_action();
373373
} elseif ('/index.php/show' == $uri && isset($_GET['id'])) {

book/security.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,9 +1546,6 @@ do the following:
15461546
),
15471547
));
15481548
1549-
.. versionadded:: 2.2
1550-
The BCrypt encoder was introduced in Symfony 2.2.
1551-
15521549
You can now calculate the hashed password either programmatically
15531550
(e.g. ``password_hash('ryanpass', PASSWORD_BCRYPT, array('cost' => 12));``)
15541551
or via some online tool.

book/templating.rst

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,12 +1487,33 @@ in a JavaScript string, use the ``js`` context:
14871487
Debugging
14881488
---------
14891489

1490-
When using PHP, you can use :phpfunction:`var_dump` if you need to quickly find
1491-
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
1493-
extension.
1490+
When using PHP, you can use the
1491+
:ref:`dump() function from the VarDumper component <components-var-dumper-dump>`
1492+
if you need to quickly find the value of a variable passed. This is useful,
1493+
for example, inside your controller::
14941494

1495-
Template parameters can then be dumped using the ``dump`` function:
1495+
// src/AppBundle/Controller/ArticleController.php
1496+
namespace AppBundle\Controller;
1497+
1498+
// ...
1499+
1500+
class ArticleController extends Controller
1501+
{
1502+
public function recentListAction()
1503+
{
1504+
$articles = ...;
1505+
dump($articles);
1506+
1507+
// ...
1508+
}
1509+
}
1510+
1511+
.. note::
1512+
1513+
The output of the ``dump()`` function is then rendered in the web developer
1514+
toolbar.
1515+
1516+
The same mechanism can be used in Twig templates thanks to ``dump`` function:
14961517

14971518
.. code-block:: html+jinja
14981519

components/filesystem/introduction.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ The Filesystem Component
66

77
The Filesystem component provides basic utilities for the filesystem.
88

9-
.. versionadded:: 2.1
10-
The Filesystem component was introduced in Symfony 2.1. Previously, the
11-
``Filesystem`` class was located in the HttpKernel component.
12-
13-
149
.. tip::
1510

1611
A lock handler feature was introduce in symfony 2.6.

components/form/introduction.rst

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -663,29 +663,45 @@ and the errors will display next to the fields on error.
663663
Accessing Form Errors
664664
~~~~~~~~~~~~~~~~~~~~~
665665

666+
.. versionadded:: 2.5
667+
Before Symfony 2.5, ``getErrors()`` returned an array of ``FormError``
668+
objects. The return value was changed to ``FormErrorIterator`` in Symfony
669+
2.5.
670+
671+
.. versionadded:: 2.5
672+
The ``$deep`` and ``$flatten`` arguments were introduced in Symfony 2.5.
673+
666674
You can use the :method:`Symfony\\Component\\Form\\FormInterface::getErrors`
667-
method to access the list of errors. Each element is a :class:`Symfony\\Component\\Form\\FormError`
668-
object::
675+
method to access the list of errors. It returns a
676+
:class:`Symfony\\Component\\Form\\FormErrorIterator` instance::
669677

670678
$form = ...;
671679

672680
// ...
673681

674-
// an array of FormError objects, but only errors attached to this form level (e.g. "global errors)
682+
// a FormErrorIterator instance, but only errors attached to this form level (e.g. "global errors)
675683
$errors = $form->getErrors();
676684

677-
// an array of FormError objects, but only errors attached to the "firstName" field
685+
// a FormErrorIterator instance, but only errors attached to the "firstName" field
678686
$errors = $form['firstName']->getErrors();
679687

680-
// a string representation of all errors of the whole form tree
681-
$errors = $form->getErrorsAsString();
688+
// a FormErrorIterator instance in a flattened structure
689+
// use getOrigin() to determine the form causing the error
690+
$errors = $form->getErrors(true);
682691

683-
.. note::
692+
// a FormErrorIterator instance representing the form tree structure
693+
$errors = $form->getErrors(true, false);
694+
695+
.. tip::
696+
697+
In older Symfony versions, ``getErrors()`` returned an array. To use the
698+
errors the same way in Symfony 2.5 or newer, you have to pass them to
699+
PHP's :phpfunction:`iterator_to_array` function::
700+
701+
$errorsAsArray = iterator_to_array($form->getErrors());
684702

685-
If you enable the :ref:`error_bubbling <reference-form-option-error-bubbling>`
686-
option on a field, calling ``getErrors()`` on the parent form will include
687-
errors from that field. However, there is no way to determine which field
688-
an error was originally attached to.
703+
This is useful, for example, if you want to use PHP's ``array_`` function
704+
on the form errors.
689705

690706
.. _Packagist: https://packagist.org/packages/symfony/form
691707
.. _Twig: http://twig.sensiolabs.org

components/var_dumper/introduction.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ You can install the component in 2 different ways:
2020
* :doc:`Install it via Composer </components/using_components>` (``symfony/var-dumper`` on `Packagist`_);
2121
* Use the official Git repository (https://github.com/symfony/var-dumper).
2222

23+
.. _components-var-dumper-dump:
24+
2325
The dump() Function
2426
-------------------
2527

contributing/documentation/overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Now you can **sync your fork** by executing the following command:
170170
$ git merge upstream/2.3
171171
172172
This command will update the ``2.3`` branch, which is the one you used to
173-
create the new branch for your changes. If have used another base branch,
173+
create the new branch for your changes. If you have used another base branch,
174174
e.g. ``master``, replace the ``2.3`` with the appropriate branch name.
175175

176176
Great! Now you can proceed by following the same steps explained in the previous

cookbook/debugging.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ below::
4747
$loader = require_once __DIR__.'/../app/autoload.php';
4848
require_once __DIR__.'/../app/AppKernel.php';
4949

50-
use Symfony\Component\HttpFoundation\Request;
51-
5250
$kernel = new AppKernel('dev', true);
5351
// $kernel->loadClassCache();
5452
$request = Request::createFromGlobals();

cookbook/form/form_collections.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,9 @@ we talk about next!).
463463

464464
.. caution::
465465

466-
If no ``addTag`` **and** ``removeTag`` method is found, the form will
467-
still use ``setTag`` even if ``by_reference`` is ``false``. You'll learn
468-
more about the ``removeTag`` method later in this article.
466+
You have to create **both** ``addTag`` and ``removeTag`` methods,
467+
otherwise the form will still use ``setTag`` even if ``by_reference`` is ``false``.
468+
You'll learn more about the ``removeTag`` method later in this article.
469469

470470
.. sidebar:: Doctrine: Cascading Relations and saving the "Inverse" side
471471

cookbook/form/form_customization.rst

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,19 @@ just one line:
6767

6868
.. code-block:: jinja
6969
70+
{# renders all fields #}
7071
{{ form_widget(form) }}
7172
73+
{# renders all fields *and* the form start and end tags #}
74+
{{ form(form) }}
75+
7276
.. code-block:: php
7377
74-
<?php echo $view['form']->widget($form); ?>
78+
<!-- renders all fields -->
79+
<?php echo $view['form']->widget($form) ?>
80+
81+
<!-- renders all fields *and* the form start and end tags -->
82+
<?php echo $view['form']->form($form) ?>
7583
7684
The remainder of this recipe will explain how every part of the form's markup
7785
can be modified at several different levels. For more information about form
@@ -93,9 +101,18 @@ rendering a form. In other words, if you want to customize one portion of
93101
how a form is rendered, you'll import a *theme* which contains a customization
94102
of the appropriate form fragments.
95103

96-
Symfony comes with a default theme (`form_div_layout.html.twig`_ in Twig and
97-
``FrameworkBundle:Form`` in PHP) that defines each and every fragment needed
98-
to render every part of a form.
104+
Symfony comes with four **built-in form themes** that define each and every
105+
fragment needed to render every part of a form:
106+
107+
* `form_div_layout.html.twig`_, wraps each form field inside a ``<div>`` element.
108+
* `form_table_layout.html.twig`_, wraps the entire form inside a ``<table>``
109+
element and each form field inside a ``<tr>`` element.
110+
* `bootstrap_3_layout.html.twig`_, wraps each form field inside a ``<div>`` element
111+
with the appropriate CSS classes to apply the default `Bootstrap 3 CSS framework`_
112+
styles.
113+
* `bootstrap_3_horizontal_layout.html.twig`_, it's similar to the previous theme,
114+
but the CSS classes applied are the ones used to display the forms horizontally
115+
(i.e. the label and the widget in the same row).
99116

100117
In the next section you will learn how to customize a theme by overriding
101118
some or all of its fragments.
@@ -1059,3 +1076,7 @@ The array passed as the second argument contains form "variables". For
10591076
more details about this concept in Twig, see :ref:`twig-reference-form-variables`.
10601077

10611078
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
1079+
.. _`form_table_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig
1080+
.. _`bootstrap_3_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig
1081+
.. _`bootstrap_3_horizontal_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig
1082+
.. _`Bootstrap 3 CSS framework`: http://getbootstrap.com/

cookbook/routing/slash_in_parameter.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ How to Allow a "/" Character in a Route Parameter
55
=================================================
66

77
Sometimes, you need to compose URLs with parameters that can contain a slash
8-
``/``. For example, take the classic ``/hello/{name}`` route. By default,
8+
``/``. For example, take the classic ``/hello/{username}`` route. By default,
99
``/hello/Fabien`` will match this route but not ``/hello/Fabien/Kris``. This
1010
is because Symfony uses this character as separator between route parts.
1111

1212
This guide covers how you can modify a route so that ``/hello/Fabien/Kris``
13-
matches the ``/hello/{name}`` route, where ``{name}`` equals ``Fabien/Kris``.
13+
matches the ``/hello/{username}`` route, where ``{username}`` equals ``Fabien/Kris``.
1414

1515
Configure the Route
1616
-------------------
@@ -27,10 +27,10 @@ a more permissive regex path.
2727
.. code-block:: yaml
2828
2929
_hello:
30-
path: /hello/{name}
30+
path: /hello/{username}
3131
defaults: { _controller: AcmeDemoBundle:Demo:hello }
3232
requirements:
33-
name: .+
33+
username: .+
3434
3535
.. code-block:: xml
3636
@@ -40,9 +40,9 @@ a more permissive regex path.
4040
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4141
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
4242
43-
<route id="_hello" path="/hello/{name}">
43+
<route id="_hello" path="/hello/{username}">
4444
<default key="_controller">AcmeDemoBundle:Demo:hello</default>
45-
<requirement key="name">.+</requirement>
45+
<requirement key="username">.+</requirement>
4646
</route>
4747
</routes>
4848
@@ -52,10 +52,10 @@ a more permissive regex path.
5252
use Symfony\Component\Routing\Route;
5353
5454
$collection = new RouteCollection();
55-
$collection->add('_hello', new Route('/hello/{name}', array(
55+
$collection->add('_hello', new Route('/hello/{username}', array(
5656
'_controller' => 'AcmeDemoBundle:Demo:hello',
5757
), array(
58-
'name' => '.+',
58+
'username' => '.+',
5959
)));
6060
6161
return $collection;
@@ -75,4 +75,4 @@ a more permissive regex path.
7575
}
7676
}
7777
78-
That's it! Now, the ``{name}`` parameter can contain the ``/`` character.
78+
That's it! Now, the ``{username}`` parameter can contain the ``/`` character.

cookbook/security/entity_provider.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,3 @@ then instead of these properties being checked, your ``isEqualTo`` method
877877
is simply called, and you can check whatever properties you want. Unless
878878
you understand this, you probably *won't* need to implement this interface
879879
or worry about it.
880-
881-
.. versionadded:: 2.1
882-
In Symfony 2.1, the ``equals`` method was removed from ``UserInterface``
883-
and the ``EquatableInterface`` was introduced in its place.

cookbook/security/target_path.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ Next, create your own ``ExceptionListener``::
6767
}
6868
}
6969

70-
Add as much or few logic here as required for your scenario!
70+
Add as much or as little logic here as required for your scenario!

reference/configuration/assetic.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
AsseticBundle Configuration ("assetic")
55
=======================================
66

7-
Full default Configuration
8-
~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
Full Default Configuration
8+
--------------------------
99

1010
.. configuration-block::
1111

0 commit comments

Comments
 (0)