Skip to content

Commit 3ecfcaf

Browse files
committed
Merge branch '2.5' into 2.6
* 2.5: 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 Fixed wrong indentation Bot fixes 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 Merging emphasized notes Adder and remover sidenote
2 parents 43809b1 + 4447b74 commit 3ecfcaf

17 files changed

+163
-106
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'])) {

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

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: 9 additions & 1 deletion
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

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/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)