Skip to content

Commit 88bd859

Browse files
ifdatticxabbuh
authored andcommitted
Update form.rst and templating.rst
1 parent 7de02d4 commit 88bd859

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

book/forms.rst

+17-14
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ from inside a controller::
7777
// src/AppBundle/Controller/DefaultController.php
7878
namespace AppBundle\Controller;
7979

80-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8180
use AppBundle\Entity\Task;
81+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8282
use Symfony\Component\HttpFoundation\Request;
8383

8484
class DefaultController extends Controller
@@ -542,16 +542,17 @@ This will call the static method ``determineValidationGroups()`` on the
542542
The Form object is passed as an argument to that method (see next example).
543543
You can also define whole logic inline by using a ``Closure``::
544544

545-
use Acme\AcmeBundle\Entity\Client;
545+
use AppBundle\Entity\Client;
546546
use Symfony\Component\Form\FormInterface;
547547
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
548548

549549
// ...
550550
public function setDefaultOptions(OptionsResolverInterface $resolver)
551551
{
552552
$resolver->setDefaults(array(
553-
'validation_groups' => function(FormInterface $form) {
553+
'validation_groups' => function (FormInterface $form) {
554554
$data = $form->getData();
555+
555556
if (Client::TYPE_PERSON == $data->getType()) {
556557
return array('person');
557558
}
@@ -565,16 +566,17 @@ Using the ``validation_groups`` option overrides the default validation
565566
group which is being used. If you want to validate the default constraints
566567
of the entity as well you have to adjust the option as follows::
567568

568-
use Acme\AcmeBundle\Entity\Client;
569+
use AppBundle\Entity\Client;
569570
use Symfony\Component\Form\FormInterface;
570571
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
571572

572573
// ...
573574
public function setDefaultOptions(OptionsResolverInterface $resolver)
574575
{
575576
$resolver->setDefaults(array(
576-
'validation_groups' => function(FormInterface $form) {
577+
'validation_groups' => function (FormInterface $form) {
577578
$data = $form->getData();
579+
578580
if (Client::TYPE_PERSON == $data->getType()) {
579581
return array('Default', 'person');
580582
}
@@ -1048,7 +1050,8 @@ that will house the logic for building the task form::
10481050
$builder
10491051
->add('task')
10501052
->add('dueDate', null, array('widget' => 'single_text'))
1051-
->add('save', 'submit');
1053+
->add('save', 'submit')
1054+
;
10521055
}
10531056

10541057
public function getName()
@@ -1123,7 +1126,8 @@ the choice is ultimately up to you.
11231126
$builder
11241127
->add('task')
11251128
->add('dueDate', null, array('mapped' => false))
1126-
->add('save', 'submit');
1129+
->add('save', 'submit')
1130+
;
11271131
}
11281132

11291133
Additionally, if there are any fields on the form that aren't included in
@@ -1155,7 +1159,7 @@ easy to use in your application.
11551159
11561160
# src/AppBundle/Resources/config/services.yml
11571161
services:
1158-
acme_demo.form.type.task:
1162+
app.form.type.task:
11591163
class: AppBundle\Form\Type\TaskType
11601164
tags:
11611165
- { name: form.type, alias: task }
@@ -1169,10 +1173,7 @@ easy to use in your application.
11691173
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
11701174
11711175
<services>
1172-
<service
1173-
id="acme_demo.form.type.task"
1174-
class="AppBundle\Form\Type\TaskType">
1175-
1176+
<service id="app.form.type.task" class="AppBundle\Form\Type\TaskType">
11761177
<tag name="form.type" alias="task" />
11771178
</service>
11781179
</services>
@@ -1183,7 +1184,7 @@ easy to use in your application.
11831184
// src/AppBundle/Resources/config/services.php
11841185
$container
11851186
->register(
1186-
'acme_demo.form.type.task',
1187+
'app.form.type.task',
11871188
'AppBundle\Form\Type\TaskType'
11881189
)
11891190
->addTag('form.type', array(
@@ -1476,6 +1477,7 @@ renders the form:
14761477
{# app/Resources/views/default/new.html.twig #}
14771478
{% form_theme form 'form/fields.html.twig' %}
14781479

1480+
{# or if you want to use multiple themes #}
14791481
{% form_theme form 'form/fields.html.twig' 'Form/fields2.html.twig' %}
14801482

14811483
{# ... render the form #}
@@ -1485,6 +1487,7 @@ renders the form:
14851487
<!-- app/Resources/views/default/new.html.php -->
14861488
<?php $view['form']->setTheme($form, array('form')) ?>
14871489

1490+
<!-- or if you want to use multiple themes -->
14881491
<?php $view['form']->setTheme($form, array('form', 'form2')) ?>
14891492

14901493
<!-- ... render the form -->
@@ -1736,7 +1739,7 @@ file:
17361739
'Form',
17371740
),
17381741
),
1739-
)
1742+
),
17401743
// ...
17411744
));
17421745

book/templating.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Throughout this chapter, template examples will be shown in both Twig and PHP.
135135
web designers everywhere.
136136

137137
Twig can also do things that PHP can't, such as whitespace control,
138-
sandboxing, automatic HTML escaping, manual contextual output escaping,
138+
sandboxing, automatic HTML escaping, manual contextual output escaping,
139139
and the inclusion of custom functions and filters that only affect templates.
140140
Twig contains little features that make writing templates easier and more concise.
141141
Take the following example, which combines a loop with a logical ``if``
@@ -206,8 +206,8 @@ First, build a base layout file:
206206
<div id="sidebar">
207207
{% block sidebar %}
208208
<ul>
209-
<li><a href="/">Home</a></li>
210-
<li><a href="/https/github.com/blog">Blog</a></li>
209+
<li><a href="/">Home</a></li>
210+
<li><a href="/https/github.com/blog">Blog</a></li>
211211
</ul>
212212
{% endblock %}
213213
</div>
@@ -663,7 +663,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
663663
{# ... #}
664664
<div id="sidebar">
665665
{{ render(controller(
666-
'AcmeArticleBundle:Article:recentArticles',
666+
'AppBundle:Article:recentArticles',
667667
{ 'max': 3 }
668668
)) }}
669669
</div>
@@ -676,7 +676,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
676676
<div id="sidebar">
677677
<?php echo $view['actions']->render(
678678
new \Symfony\Component\HttpKernel\Controller\ControllerReference(
679-
'AcmeArticleBundle:Article:recentArticles',
679+
'AppBundle:Article:recentArticles',
680680
array('max' => 3)
681681
)
682682
) ?>
@@ -796,7 +796,7 @@ in your application configuration:
796796
// app/config/config.php
797797
$container->loadFromExtension('framework', array(
798798
// ...
799-
'templating' => array(
799+
'templating' => array(
800800
'hinclude_default_template' => array(
801801
'hinclude.html.twig',
802802
),
@@ -823,7 +823,7 @@ any global default template that is defined):
823823
new ControllerReference('...'),
824824
array(
825825
'renderer' => 'hinclude',
826-
'default' => 'default/content.html.twig',
826+
'default' => 'default/content.html.twig',
827827
)
828828
) ?>
829829
@@ -841,7 +841,7 @@ Or you can also specify a string to display as the default content:
841841
new ControllerReference('...'),
842842
array(
843843
'renderer' => 'hinclude',
844-
'default' => 'Loading...',
844+
'default' => 'Loading...',
845845
)
846846
) ?>
847847
@@ -1014,13 +1014,13 @@ but Symfony provides a more dynamic option via the ``asset`` Twig function:
10141014

10151015
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
10161016

1017-
<link href="{{ asset('css/blog.css') }}" rel="stylesheet" type="text/css" />
1017+
<link href="{{ asset('css/blog.css') }}" rel="stylesheet" />
10181018

10191019
.. code-block:: html+php
10201020

10211021
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" />
10221022

1023-
<link href="<?php echo $view['assets']->getUrl('css/blog.css') ?>" rel="stylesheet" type="text/css" />
1023+
<link href="<?php echo $view['assets']->getUrl('css/blog.css') ?>" rel="stylesheet" />
10241024

10251025
The ``asset`` function's main purpose is to make your application more portable.
10261026
If your application lives at the root of your host (e.g. http://example.com),
@@ -1145,7 +1145,7 @@ is by default "web").
11451145

11461146
.. code-block:: html+jinja
11471147

1148-
<link href="{{ asset('bundles/acmedemo/css/contact.css') }}" rel="stylesheet" />
1148+
<link href="{{ asset('bundles/acmedemo/css/contact.css') }}" rel="stylesheet" />
11491149

11501150
The end result is a page that includes both the ``main.css`` and ``contact.css``
11511151
stylesheets.
@@ -1364,7 +1364,7 @@ One common way to use inheritance is to use a three-level approach. This
13641364
method works perfectly with the three different types of templates that were just
13651365
covered:
13661366

1367-
* Create a ``app/Resources/views/base.html.twig`` file that contains the main
1367+
* Create an ``app/Resources/views/base.html.twig`` file that contains the main
13681368
layout for your application (like in the previous example). Internally, this
13691369
template is called ``base.html.twig``;
13701370

@@ -1455,7 +1455,7 @@ tag to the screen:
14551455

14561456
.. code-block:: html
14571457

1458-
Hello &lt;script&gt;alert(&#39;helloe&#39;)&lt;/script&gt;
1458+
Hello &lt;script&gt;alert(&#39;hello!&#39;)&lt;/script&gt;
14591459

14601460
The Twig and PHP templating systems approach the problem in different ways.
14611461
If you're using Twig, output escaping is on by default and you're protected.

0 commit comments

Comments
 (0)