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

File tree

23 files changed

+209
-138
lines changed

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

0 commit comments

Comments
 (0)