Skip to content

Commit 2c10e1d

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: Updated according to comments Improved nginx config to not expose other php files [Form] fixed EntityType choice options Adding information about using the date type as usable date picker field
2 parents a74dddd + 1a600cd commit 2c10e1d

File tree

3 files changed

+113
-29
lines changed

3 files changed

+113
-29
lines changed

cookbook/configuration/web_server_configuration.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ The **minimum configuration** to get your application running under Nginx is:
305305
# Remove the internal directive to allow URIs like this
306306
internal;
307307
}
308+
309+
# return 404 for all other php files not matching the front controller
310+
# this prevents access to other php files you don't want to be accessible.
311+
location ~ \.php$ {
312+
return 404;
313+
}
308314
309315
error_log /var/log/nginx/project_error.log;
310316
access_log /var/log/nginx/project_access.log;
@@ -318,14 +324,17 @@ The **minimum configuration** to get your application running under Nginx is:
318324
.. tip::
319325

320326
This executes **only** ``app.php``, ``app_dev.php`` and ``config.php`` in
321-
the web directory. All other files will be served as text. You **must**
322-
also make sure that if you *do* deploy ``app_dev.php`` or ``config.php``
323-
that these files are secured and not available to any outside user (the
324-
IP address checking code at the top of each file does this by default).
327+
the web directory. All other files ending in ".php" will be denied.
325328

326329
If you have other PHP files in your web directory that need to be executed,
327330
be sure to include them in the ``location`` block above.
328331

332+
.. caution::
333+
334+
After you deploy to production, make sure that you **cannot** access the ``app_dev.php``
335+
or ``config.php`` scripts (i.e. ``http://example.com/app_dev.php`` and ``http://example.com/config.php``).
336+
If you *can* access these, be sure to remove the ``DEV`` section from the above configuration.
337+
329338
For advanced Nginx configuration options, read the official `Nginx documentation`_.
330339

331340
.. _`Apache documentation`: http://httpd.apache.org/docs/

reference/forms/types/date.rst

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ DateType Field
77
A field that allows the user to modify date information via a variety of
88
different HTML elements.
99

10-
The underlying data used for this field type can be a ``DateTime`` object,
11-
a string, a timestamp or an array. As long as the `input`_ option is set
12-
correctly, the field will take care of all of the details.
13-
14-
The field can be rendered as a single text box, three text boxes (month,
15-
day and year) or three select boxes (see the `widget`_ option).
10+
This field can be rendered in a variety of different ways via the `widget`_ option
11+
and can understand a number of different input formats via the `input`_ option.
1612

1713
+----------------------+-----------------------------------------------------------------------------+
1814
| Underlying Data Type | can be ``DateTime``, string, timestamp, or array (see the ``input`` option) |
@@ -56,31 +52,78 @@ This field type is highly configurable, but easy to use. The most important
5652
options are ``input`` and ``widget``.
5753

5854
Suppose that you have a ``publishedAt`` field whose underlying date is a
59-
``DateTime`` object. The following configures the ``DateType`` type for that
60-
field as three different choice fields::
55+
``DateTime`` object. The following configures the ``date`` type for that
56+
field as **three different choice fields**::
6157

6258
use Symfony\Component\Form\Extension\Core\Type\DateType;
6359
// ...
6460

6561
$builder->add('publishedAt', DateType::class, array(
66-
'input' => 'datetime',
6762
'widget' => 'choice',
6863
));
6964

70-
The ``input`` option *must* be changed to match the type of the underlying
71-
date data. For example, if the ``publishedAt`` field's data were a unix
72-
timestamp, you'd need to set ``input`` to ``timestamp``::
65+
If your underlying date is *not* a ``DateTime`` object (e.g. it's a unix timestamp),
66+
configure the `input`_ option.
67+
68+
Rendering a single HTML5 Textbox
69+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70+
71+
For a better user experience, you may want to render a single text field and use
72+
some kind of "date picker" to help your user fill in the right format. To do that,
73+
use the ``single_text`` widget::
7374

7475
use Symfony\Component\Form\Extension\Core\Type\DateType;
7576
// ...
7677

7778
$builder->add('publishedAt', DateType::class, array(
78-
'input' => 'timestamp',
79-
'widget' => 'choice',
79+
// render as a single text box
80+
'widget' => 'single_text',
81+
));
82+
83+
This will render as an ``input type="date"`` HTML5 field, which means that **some -
84+
but not all - browsers will add nice date picker functionality to the field**. If you
85+
want to be absolutely sure that *every* user has a consistent date picker, use an
86+
external JavaScript library.
87+
88+
For example, suppose you want to use the `Bootstrap Datepicker`_ library. First,
89+
make the following changes::
90+
91+
use Symfony\Component\Form\Extension\Core\Type\DateType;
92+
// ...
93+
94+
$builder->add('publishedAt', DateType::class, array(
95+
'widget' => 'single_text',
96+
97+
// do not render as type="date", to avoid HTML5 date pickers
98+
'html5' => false,
99+
100+
// add a class that can eb selected in JavaScript
101+
'attr' => ['class' => 'js-datepicker'],
80102
));
81103

82-
The field also supports an ``array`` and ``string`` as valid ``input`` option
83-
values.
104+
Assuming you're using jQuery, you can initialize the date picker via:
105+
106+
.. code-block:: html
107+
108+
<script>
109+
$(document).ready(function() {
110+
$('.js-datepicker').datepicker({
111+
format: 'yyyy-mm-dd'
112+
});
113+
});
114+
</script>
115+
116+
This ``format`` key tells the date picker to use the date format that Symfony expects.
117+
This can be tricky: if the date picker is misconfigured, Symfony won't understand
118+
the format and will throw a validation error. You can also configure the format
119+
that Symfony should expect via the `format`_ option.
120+
121+
.. caution::
122+
123+
The string used by a JavaScript date picker to describe its format (e.g. ``yyyy-mm-dd``)
124+
may not match the string that Symfony uses (e.g. ``yyyy-MM-dd``). This is because
125+
different libraries use different formatting rules to describe the date format.
126+
Be aware of this - it can be tricky to make the formats truly match!
84127

85128
Field Options
86129
-------------
@@ -182,3 +225,5 @@ Field Variables
182225
+--------------+------------+----------------------------------------------------------------------+
183226
| date_pattern | ``string`` | A string with the date format to use. |
184227
+--------------+------------+----------------------------------------------------------------------+
228+
229+
.. _`Bootstrap Datepicker`: https://github.com/eternicode/bootstrap-datepicker

reference/forms/types/entity.rst

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ objects from the database.
1717
| | - `em`_ |
1818
| | - `query_builder`_ |
1919
+-------------+------------------------------------------------------------------+
20-
| Overridden | - `choices`_ |
21-
| options | - `data_class`_ |
20+
| Overridden | - `choice_name`_ |
21+
| options | - `choice_value`_ |
22+
| | - `choices`_ |
23+
| | - `data_class`_ |
2224
+-------------+------------------------------------------------------------------+
2325
| Inherited | from the :doc:`ChoiceType </reference/forms/types/choice>`: |
2426
| options | |
2527
| | - `choice_attr`_ |
26-
| | - `choice_name`_ |
2728
| | - `choice_translation_domain`_ |
28-
| | - `choice_value`_ |
2929
| | - `expanded`_ |
3030
| | - `group_by`_ |
3131
| | - `multiple`_ |
@@ -126,7 +126,7 @@ Field Options
126126
choice_label
127127
~~~~~~~~~~~~
128128

129-
**type**: ``string`` or ``callable``
129+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath`
130130

131131
This is the property that should be used for displaying the entities as text in
132132
the HTML element::
@@ -208,6 +208,40 @@ the Closure.
208208
Overridden Options
209209
------------------
210210

211+
choice_name
212+
~~~~~~~~~~~
213+
214+
.. versionadded:: 2.7
215+
The ``choice_name`` option was introduced in Symfony 2.7.
216+
217+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id
218+
219+
By default the name of each field is the id of the entity, if it can be read
220+
from the class metadata by an internal id reader. Otherwise the process will
221+
fall back to using increasing integers.
222+
223+
choice_value
224+
~~~~~~~~~~~~
225+
226+
.. versionadded:: 2.7
227+
The ``choice_value`` option was introduced in Symfony 2.7.
228+
229+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id
230+
231+
As for the ``choice_name`` option, ``choice_value`` uses the id by default.
232+
It allows an optimization in the :class:``Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\Loader\\DoctrineChoiceLoader`` which will
233+
only load the ids passed as values while the form submission.
234+
It prevents all non submitted entities to be loaded from the database, even
235+
when defining the ``query_builder`` option.
236+
If it may be useful to set this option using an entity's property as string
237+
value (e.g for some API), you will gain performances by letting this option set
238+
by default.
239+
240+
.. note::
241+
242+
If the id cannot be read, for BC, the component checks if the class implements
243+
``__toString()`` and will use an incremental integer otherwise.
244+
211245
choices
212246
~~~~~~~
213247

@@ -232,12 +266,8 @@ These options inherit from the :doc:`ChoiceType </reference/forms/types/choice>`
232266

233267
.. include:: /reference/forms/types/options/choice_attr.rst.inc
234268

235-
.. include:: /reference/forms/types/options/choice_name.rst.inc
236-
237269
.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc
238270

239-
.. include:: /reference/forms/types/options/choice_value.rst.inc
240-
241271
.. include:: /reference/forms/types/options/expanded.rst.inc
242272

243273
.. include:: /reference/forms/types/options/group_by.rst.inc

0 commit comments

Comments
 (0)