8000 Merge branch '2.3' into 2.4 · symfony/symfony-docs@b123484 · GitHub
[go: up one dir, main page]

Skip to content

Commit b123484

Browse files
committed
Merge branch '2.3' into 2.4
2 parents 0a21718 + d611e77 commit b123484

File tree

5 files changed

+88
-28
lines changed

5 files changed

+88
-28
lines changed

book/forms.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ learning the most important features of the form library along the way.
1313

1414
The Symfony Form component is a standalone library that can be used outside
1515
of Symfony2 projects. For more information, see the `Symfony2 Form component`_
16-
on Github.
16+
on GitHub.
1717

1818
.. index::
1919
single: Forms; Create a simple form
@@ -39,6 +39,7 @@ going to need to build a form. But before you begin, first focus on the generic
3939
{
4040
return $this->task;
4141
}
42+
4243
public function setTask($task)
4344
{
4445
$this->task = $task;
@@ -48,7 +49,7 @@ going to need to build a form. But before you begin, first focus on the generic
4849
{
4950
return $this->dueDate;
5051
}
51-
52+
5253
public function setDueDate(\DateTime $dueDate = null)
5354
{
5455
$this->dueDate = $dueDate;
@@ -172,7 +173,7 @@ helper functions:
172173

173174
That's it! By printing ``form(form)``, each field in the form is rendered, along
174175
with a label and error message (if there is one). The ``form`` function also
175-
surrounds everything in the necessary HTML ``form`` tag. As easy as this is,
176+
surrounds everything in the necessary HTML ``<form>`` tag. As easy as this is,
176177
it's not very flexible (yet). Usually, you'll want to render each form field
177178
individually so you can control how the form looks. You'll learn how to do
178179
that in the ":ref:`form-rendering-template`" section.
@@ -267,7 +268,8 @@ possible paths:
267268
.. note::
268269

269270
Redirecting a user after a successful form submission prevents the user
270-
from being able to hit "refresh" and re-post the data.
271+
from being able to hit the "Refresh" button of their browser and re-post
272+
the data.
271273

272274
.. index::
273275
single: Forms; Multiple Submit Buttons
@@ -566,7 +568,7 @@ First, we need to add the two buttons to the form::
566568

567569
Then, we configure the button for returning to the previous step to run
568570
specific validation groups. In this example, we want it to suppress validation,
569-
so we set its ``validation_groups`` options to false::
571+
so we set its ``validation_groups`` option to false::
570572

571573
$form = $this->createFormBuilder($task)
572574
// ...
@@ -979,10 +981,10 @@ to the ``form()`` or the ``form_start()`` helper:
979981
.. note::
980982

981983
If the form's method is not GET or POST, but PUT, PATCH or DELETE, Symfony2
982-
will insert a hidden field with the name "_method" that stores this method.
984+
will insert a hidden field with the name ``_method`` that stores this method.
983985
The form will be submitted in a normal POST request, but Symfony2's router
984-
is capable of detecting the "_method" parameter and will interpret the
985-
request as PUT, PATCH or DELETE request. Read the cookbook chapter
986+
is capable of detecting the ``_method`` parameter and will interpret it as
987+
a PUT, PATCH or DELETE request. Read the cookbook chapter
986988
":doc:`/cookbook/routing/method_parameters`" for more information.
987989

988990
.. index::
@@ -1076,7 +1078,8 @@ the choice is ultimately up to you.
10761078

10771079
public function buildForm(FormBuilderInterface $builder, array $options)
10781080
{
1079-
$builder->add('task')
1081+
$builder
1082+
->add('task')
10801083
->add('dueDate', null, array('mapped' => false))
10811084
->add('save', 'submit');
10821085
}
@@ -1316,8 +1319,7 @@ the ``cascade_validation`` option to ``TaskType``::
13161319
));
13171320
}
13181321
1319-
Render the ``Category`` fields in the same way
1320-
as the original ``Task`` fields:
1322+
Render the ``Category`` fields in the same way as the original ``Task`` fields:
13211323
13221324
.. configuration-block::
13231325

book/routing.rst

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,10 +1224,10 @@ Generating URLs
12241224
---------------
12251225

12261226
The routing system should also be used to generate URLs. In reality, routing
1227-
is a bi-directional system: mapping the URL to a controller+parameters and
1227+
is a bidirectional system: mapping the URL to a controller+parameters and
12281228
a route+parameters back to a URL. The
12291229
:method:`Symfony\\Component\\Routing\\Router::match` and
1230-
:method:`Symfony\\Component\\Routing\\Router::generate` methods form this bi-directional
1230+
:method:`Symfony\\Component\\Routing\\Router::generate` methods form this bidirectional
12311231
system. Take the ``blog_show`` example route from earlier::
12321232

12331233
$params = $this->get('router')->match('/blog/my-blog-post');
@@ -1258,12 +1258,25 @@ route. With this information, any URL can easily be generated::
12581258

12591259
.. note::
12601260

1261-
In controllers that extend Symfony's base
1261+
In controllers that don't extend Symfony's base
12621262
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`,
1263-
you can use the
1264-
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::generateUrl`
1265-
method, which calls the router service's
1266-
:method:`Symfony\\Component\\Routing\\Router::generate` method.
1263+
you can use the ``router`` service's
1264+
:method:`Symfony\\Component\\Routing\\Router::generate` method::
1265+
1266+
use Symfony\Component\DependencyInjection\ContainerAware;
1267+
1268+
class MainController extends ContainerAware
1269+
{
1270+
public function showAction($slug)
1271+
{
1272+
// ...
1273+
1274+
$url = $this->container->get('router')->generate(
1275+
'blog_show',
1276+
array('slug' => 'my-blog-post')
1277+
);
1278+
}
1279+
}
12671280

12681281
In an upcoming section, you'll learn how to generate URLs from inside templates.
12691282

@@ -1352,19 +1365,19 @@ to ``generateUrl()``:
13521365

13531366
.. note::
13541367

1355-
The host that's used when generating an absolute URL is the host of
1356-
the current ``Request`` object. This is detected automatically. But if
1357-
you generate absolute URLs for scripts run from the command line, this
1358-
won't work. But don't worry! Just see :doc:`/cookbook/console/sending_emails`
1359-
for details.
1368+
The host that's used when generating an absolute URL is automatically
1369+
detected using the current ``Request`` object. When generating absolute
1370+
URLs from outside the web context (for instance in a console command) this
1371+
doesn't work. See :doc:`/cookbook/console/sending_emails` to learn how to
1372+
solve this problem.
13601373

13611374
Summary
13621375
-------
13631376

13641377
Routing is a system for mapping the URL of incoming requests to the controller
13651378
function that should be called to process the request. It both allows you
13661379
to specify beautiful URLs and keeps the functionality of your application
1367-
decoupled from those URLs. Routing is a two-way mechanism, meaning that it
1380+
decoupled from those URLs. Routing is a bidirectional mechanism, meaning that it
13681381
should also be used to generate URLs.
13691382

13701383
Learn more from the Cookbook

components/console/helpers/dialoghelper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ method::
113113
'Please enter the name of the bundle',
114114
function ($answer) {
115115
if ('Bundle' !== substr($answer, -6)) {
116-
throw new \RunTimeException(
116+
throw new \RuntimeException(
117117
'The name of the bundle should be suffixed with \'Bundle\''
118118
);
119119
}

components/serializer.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,37 @@ method on the normalizer definition::
181181
As a final result, the deserializer uses the ``first_name`` attribute as if
182182
it were ``firstName`` and uses the ``getFirstName`` and ``setFirstName`` methods.
183183

184+
Using Callbacks to Serialize Properties with Object Instances
185+
-------------------------------------------------------------
186+
187+
When serializing, you can set a callback to format a specific object property::
188+
189+
use Acme\Person;
190+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
191+
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
192+
use Symfony\Component\Serializer\Serializer;
193+
194+
$encoder = new JsonEncoder();
195+
$normalizer = new GetSetMethodNormalizer();
196+
197+
$callback = function ($dateTime) {
198+
return $dateTime instanceof \DateTime
199+
? $dateTime->format(\DateTime::ISO8601)
200+
: '';
201+
}
202+
203+
$normalizer->setCallbacks(array('createdAt' => $callback));
204+
205+
$serializer = new Serializer(array($normalizer), array($encoder));
206+
207+
$person = new Person();
208+
$person->setName('cordoval');
209+
$person->setAge(34);
210+
$person->setCreatedAt(new \DateTime('now'));
211+
212+
$serializer->serialize($person, 'json');
213+
// Output: {"name":"cordoval", "age": 34, "createdAt": "2014-03-22T09:43:12-0500"}
214+
184215
JMSSerializer
185216
-------------
186217

reference/dic_tags.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,23 @@ To register your warmer with Symfony, give it the ``kernel.cache_warmer`` tag:
477477
->addTag('kernel.cache_warmer', array('priority' => 0))
478478
;
479479
480-
The ``priority`` value is optional, and defaults to 0. This value can be
481-
from -255 to 255, and the warmers will be executed in the order of their
482-
priority.
480+
.. note::
481+
482+
The ``priority`` value is optional, and defaults to 0.
483+
The higher the priority, the sooner it gets executed.
484+
485+
Core Cache Warmers
486+
~~~~~~~~~~~~~~~~~~
487+
488+
+-------------------------------------------------------------------------------------------+-----------+
489+
| Cache Warmer Class Name | Priority |
490+
+-------------------------------------------------------------------------------------------+-----------+
491+
| :class:`Symfony\\Bundle\\FrameworkBundle\\CacheWarmer\\TemplatePathsCacheWarmer` | 20 |
492+
+-------------------------------------------------------------------------------------------+-----------+
493+
| :class:`Symfony\\Bundle\\FrameworkBundle\\CacheWarmer\\RouterCacheWarmer` | 0 |
494+
+-------------------------------------------------------------------------------------------+-----------+
495+
| :class:`Symfony\\Bundle\\TwigBundle\\CacheWarmer\\TemplateCacheCacheWarmer` | 0 |
496+
+-------------------------------------------------------------------------------------------+-----------+
483497
484498
.. _dic-tags-kernel-event-listener:
485499

0 commit comments

Comments
 (0)
0