File tree

15 files changed

+141
-47
lines changed

15 files changed

+141
-47
lines changed
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ specify it:
725725

726726
<?php echo $view['form']->label($form['task'], 'Task Description') ?>
727727

728-
Finally, some field types have additional rendering options that can be passed
728+
Some field types have additional rendering options that can be passed
729729
to the widget. These options are documented with each type, but one common
730730
options is ``attr``, which allows you to modify attributes on the form element.
731731
The following would add the ``task_field`` class to the rendered input text
@@ -743,6 +743,33 @@ field:
743743
'attr' => array('class' => 'task_field'),
744744
)) ?>
745745

746+
If you need to render form fields "by hand" then you can access individual
747+
values for fields such as the ``id``, ``name`` and ``label``. For example
748+
to get the ``id``:
749+
750+
.. configuration-block::
751+
752+
.. code-block:: html+jinja
753+
754+
{{ form.task.vars.id }}
755+
756+
.. code-block:: html+php
757+
758+
<?php echo $form['task']->get('id') ?>
759+
760+
To get the value used for the form field's name attribute you need to use
761+
the ``full_name`` value:
762+
763+
.. configuration-block::
764+
765+
.. code-block:: html+jinja
766+
767+
{{ form.task.vars.full_name }}
768+
769+
.. code-block:: html+php
770+
771+
<?php echo $form['task']->get('full_name') ?>
772+
746773
Twig Template Function Reference
747774
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
748775

@@ -830,15 +857,15 @@ the choice is ultimately up to you.
830857
}
831858

832859
.. tip::
833-
834-
When mapping forms to objects, all fields are mapped. Any fields on the
835-
form that do not exist on the mapped object will cause an exception to
836-
be thrown.
837-
838-
In cases where you need extra fields in the form (for example: a "do you
839-
agree with these terms" checkbox) that will not be mapped to the underlying
840-
object, you need to set the property_path option to ``false``::
841-
860+
861+
When mapping forms to objects, all fields are mapped. Any fields on the
862+
form that do not exist on the mapped object will cause an exception to
863+
be thrown.
864+
865+
In cases where you need extra fields in the form (for example: a "do you
866+
agree with these terms" checkbox) that will not be mapped to the underlying
867+
object, you need to set the property_path option to ``false``::
868+
842869
public function buildForm(FormBuilder $builder, array $options)
843870
{
844871
$builder->add('task');
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ finely tuned via a set of options you can set by overriding the ``getOptions()``
173173
method::
174174

175175
// app/AppCache.php
176-
class AppCache extends Cache
176+
177+
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
178+
179+
class AppCache extends HttpCache
177180
{
178181
protected function getOptions()
179182
{
@@ -654,7 +657,7 @@ exposing a simple and efficient pattern::
654657
} else {
655658
// do more work here - like retrieving more data
656659
$comments = // ...
657-
660+
658661
// or render a template with the $response you've already started
659662
return $this->render(
660663
'MyBundle:MyController:article.html.twig',
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ the user is connecting via a secured connection (i.e. ``https``).
263263
In fact, every public property used in the previous example is some instance
264264
of the ParameterBag.
265265

266+
.. _book-fundamentals-attributes:
267+
266268
The Request class also has a public ``attributes`` property, which holds
267269
special data related to how the application works internally. For the
268270
Symfony2 framework, the ``attributes`` holds the values returned by the
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ command:
3131
$ phpunit -c app/
3232
3333
The ``-c`` option tells PHPUnit to look in the ``app/`` directory for a configuration
34-
file. If you're curious about how the PHPUnit options, check out the ``app/phpunit.xml.dist``
34+
file. If you're curious about the PHPUnit options, check out the ``app/phpunit.xml.dist``
3535
file.
3636

3737
.. tip::
@@ -258,10 +258,10 @@ document::
258258
To get you started faster, here is a list of the most common and
259259
useful test assertions::
260260
261-
// Assert that there is exactly one h2 tag with the class "subtitle"
261+
// Assert that there is more than one h2 tag with the class "subtitle"
262262
$this->assertTrue($crawler->filter('h2.subtitle')->count() > 0);
263263
264-
// Assert that there are 4 h2 tags on the page
264+
// Assert that there are exactly 4 h2 tags on the page
265265
$this->assertEquals(4, $crawler->filter('h2')->count());
266266
267267
// Assert the the "Content-Type" header is "application/json"
@@ -288,7 +288,7 @@ document::
288288
Working with the Test Client
289289
-----------------------------
290290

291-
The test Client simulates an HTTP client like a browser and makes requests
291+
The Test Client simulates an HTTP client like a browser and makes requests
292292
into your Symfony2 application::
293293

294294
$crawler = $client->request('GET', '/hello/Fabien');
@@ -486,9 +486,9 @@ Many other methods are also available:
486486
+------------------------+----------------------------------------------------+
487487
| ``previousAll()`` | All preceding siblings |
488488
+------------------------+----------------------------------------------------+
489-
| ``parents()`` | Parent nodes |
489+
| ``parents()`` | Returns the parent nodes |
490490
+------------------------+----------------------------------------------------+
491-
| ``children()`` | Children |
491+
| ``children()`` | Returns children nodes |
492492
+------------------------+----------------------------------------------------+
493493
| ``reduce($lambda)`` | Nodes for which the callable does not return false |
494494
+------------------------+----------------------------------------------------+
@@ -591,7 +591,7 @@ that overrides the default ones::
591591
And if you want to simulate a specific HTTP method for the form, pass it as a
592592
second argument::
593593

594-
$form = $crawler->form(array(), 'DELETE');
594+
$form = $buttonCrawlerNode->form(array(), 'DELETE');
595595

596596
The Client can submit ``Form`` instances::
597597

Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ add the following to it::
6868
}
6969
}
7070

71+
You also need to create the file to run at the command line which creates
72+
an ``Application`` and adds commands to it:
73+
74+
.. code-block::php
75+
76+
#!/usr/bin/env php
77+
# app/console
78+
<?php
79+
80+
use Acme\DemoBundle\Command\GreetCommand;
81+
use Symfony\Component\Console\Application;
82+
83+
$application = new Application();
84+
$application->add(new GreetCommand);
85+
$application->run();
86+
7187
Test the new console command by running the following
7288

7389
.. code-block:: bash
@@ -247,8 +263,7 @@ console::
247263
{
248264
public function testExecute()
249265
{
250-
// mock the Kernel or create one depending on your needs
251-
$application = new Application($kernel);
266+
$application = new Application();
252267
$application->add(new GreetCommand());
253268

254269
$command = $application->find('demo:greet');
@@ -265,31 +280,39 @@ The :method:`Symfony\\Component\\Console\\Tester\\CommandTester::getDisplay`
265280
method returns what would have been displayed during a normal call from the
266281
console.
267282

268-
.. tip::
283+
You can test sending arguments and options to the command by passing them
284+
as an array to the :method:`Symfony\\Component\\Console\\Tester\\CommandTester::getDisplay`
285+
method::
269286

270-
You can also test a whole console application by using
271-
:class:`Symfony\\Component\\Console\\Tester\\ApplicationTester`.
287+
use Symfony\Component\Console\Tester\CommandTester;
288+
use Symfony\Bundle\FrameworkBundle\Console\Application;
289+
use Acme\DemoBundle\Command\GreetCommand;
272290

273-
Getting Services from the Service Container
274-
-------------------------------------------
291+
class ListCommandTest extends \PHPUnit_Framework_TestCase
292+
{
275293

276-
By using :class:`Symfony\\Bundle\\FrameworkBundle\\Command\\ContainerAwareCommand`
277-
as the base class for the command (instead of the more basic
278-
:class:`Symfony\\Component\\Console\\Command\\Command`), you have access to the
279-
service container. In other words, you have access to any configured service.
280-
For example, you could easily extend the task to be translatable::
294+
//--
281295

282-
protected function execute(InputInterface $input, OutputInterface $output)
283-
{
284-
$name = $input->getArgument('name');
285-
$translator = $this->getContainer()->get('translator');
286-
if ($name) {
287-
$output->writeln($translator->trans('Hello %name%!', array('%name%' => $name)));
288-
} else {
289-
$output->writeln($translator->trans('Hello!'));
296+
public function testNameIsOutput()
297+
{
298+
$application = new Application();
299+
$application->add(new GreetCommand());
300+
301+
$command = $application->find('demo:greet');
302+
$commandTester = new CommandTester($command);
303+
$commandTester->execute(
304+
array('command' => $command->getName(), 'name' => 'Fabien')
305+
);
306+
307+
$this->assertRegExp('/Fabien/', $commandTester->getDisplay());
290308
}
291309
}
292310

311+
.. tip::
312+
313+
You can also test a whole console application by using
314+
:class:`Symfony\\Component\\Console\\Tester\\ApplicationTester`.
315+
293316
Calling an existing Command
294317
---------------------------
295318

Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ directly::
306306

307307
use Goutte\Client;
308308

309-
// make a real reqeust to an external site
309+
// make a real request to an external site
310310
$client = new Client();
311311
$crawler = $client->request('GET', 'https://.com/login');
312312

Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ can be accessed via several public properties:
5252

5353
* ``cookies``: equivalent of ``$_COOKIE``;
5454

55+
* ``attributes``: no equivalent - used by your app to store other data (see :ref:`below<component-foundation-attributes>`)
56+
5557
* ``files``: equivalent of ``$_FILE``;
5658

5759
* ``server``: equivalent of ``$_SERVER``;
@@ -68,6 +70,8 @@ instance (or a sub-class of), which is a data holder class:
6870

6971
* ``cookies``: :class:`Symfony\\Component\\HttpFoundation\\ParameterBag`;
7072

73+
* ``attributes``: :class:`Symfony\\Component\\HttpFoundation\\ParameterBag`;
74+
7175
* ``files``: :class:`Symfony\\Component\\HttpFoundation\\FileBag`;
7276

7377
* ``server``: :class:`Symfony\\Component\\HttpFoundation\\ServerBag`;
@@ -154,11 +158,14 @@ argument::
154158
$request->query->get('foo[bar]', null, true);
155159
// returns 'bar'
156160

161+
.. _component-foundation-attributes:
162+
157163
Last, but not the least, you can also store additional data in the request,
158164
thanks to the ``attributes`` public property, which is also an instance of
159165
:class:`Symfony\\Component\\HttpFoundation\\ParameterBag`. This is mostly used
160166
to attach information that belongs to the Request and that needs to be
161-
accessed from many different points in your application.
167+
accessed from many different points in your application. For information
168+
on how this is used in the Symfony2 framework, see :ref:`read more<book-fundamentals-attributes>`.
162169

163170
Identifying a Request
164171
~~~~~~~~~~~~~~~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ mapping type:
148148
# app/config/config.yml
149149
doctrine:
150150
dbal:
151-
connection:
151+
connections:
152152
default:
153153
// Other connections parameters
154154
mapping_types:
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ we want to always render it in a ``ul`` element. In your form theme template
106106

107107
.. code-block:: html+jinja
108108

109-
{# src/Acme/DemoBundle/Resources/Form/fields.html.twig #}
109+
{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
110110

111111
{% block gender_widget %}
112112
{% spaceless %}
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ to the ``NewsletterManager`` class, the config would look like this:
412412
)->addMethodCall('setMailer', array(
413413
new Reference('my_alternative_mailer')
414414
));
415-
$container->setDefinition('newsletter_manager', new DefinitionDecorator(
415+
$container->setDefinition('greeting_card_manager', new DefinitionDecorator(
416416
'mail_manager'
417417
))->setClass(
418418
'%greeting_card_manager.class%'
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Understanding Scopes
1010
--------------------
1111

1212
The scope of a service controls how long an instance of a service is used
13-
by the container. the Dependency Injection component provides two generic
13+
by the container. The Dependency Injection component provides two generic
1414
scopes:
1515

1616
- `container` (the default one): The same instance is used each time you
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ At this point, you have a fully-functional Symfony2 project that's correctly
6969
committed to git. You can immediately begin development, committing the new
7070
changes to your git repository.
7171

72+
.. tip::
73+
74+
After execution of the command:
75+
76+
.. code-block:: bash
77+
78+
$ php bin/vendors install
79+
80+
your project will contain complete the git history of all the bundles
81+
and libraries defined in the ``deps`` file. It can be as much as 100 MB!
82+
You can remove the git history directories with the following command:
83+
84+
.. code-block:: bash
85+
86+
$ find vendor -name .git -type d | xargs rm -rf
87+
88+
The command removes all ``.git`` directories contained inside the
89+
``vendor`` directory.
90+
91+
If you want to update bundles defined in ``deps`` file after this, you
92+
will have to reinstall them:
93+
94+
.. code-block:: bash
95+
96+
$ php bin/vendors install --reinstall
97+
7298
You can continue to follow along with the :doc:`/book/page_creation` chapter
7399
to learn more about how to configure and develop inside your application.
74100

Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Field Options
7878
empty_value
7979
~~~~~~~~~~~
8080

81-
**type**: ``string``|``array``
81+
**type**: ``string`` or ``array``
8282

8383
If your widget option is set to ``choice``, then this field will be represented
8484
as a series of ``select`` boxes. The ``empty_value`` option can be used to
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ data can be a ``DateTime`` object, a string, a timestamp or an array.
1919
| | - `time_widget`_ |
2020
| | - `input`_ |
2121
| | - `date_format`_ |
22+
| | - `hours`_ |
23+
| | - `minutes`_ |
24+
| | - `seconds`_ |
2225
| | - `years`_ |
2326
| | - `months`_ |
2427
| | - `days`_ |
28+
| | - `with_seconds`_ |
29+
| | - `data_timezone`_ |
30+
| | - `user_timezone`_ |
2531
+----------------------+-----------------------------------------------------------------------------+
2632
| Parent type | :doc:`form</reference/forms/types/form>` |
2733
+----------------------+-----------------------------------------------------------------------------+
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ have a protocol.
1111
+-------------+-------------------------------------------------------------------+
1212
| Rendered as | ``input url`` field |
1313
+-------------+-------------------------------------------------------------------+
14-
| Options | - ``default_protocol`` |
14+
| Options | - `default_protocol`_ |
1515
+-------------+-------------------------------------------------------------------+
1616
| Inherited | - `max_length`_ |
1717
| options | - `required`_ |

0 commit comments

Comments
 (0)