Skip to content

Commit 1e30de8

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: Updated according to comments Improved nginx config to not expose other php files Adding information about using the date type as usable date picker field
2 parents 439283a + 90a2922 commit 1e30de8

File tree

2 files changed

+70
-19
lines changed

2 files changed

+70
-19
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: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ date Field Type
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) |
@@ -57,24 +53,68 @@ options are ``input`` and ``widget``.
5753

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

6258
$builder->add('publishedAt', 'date', array(
63-
'input' => 'datetime',
6459
'widget' => 'choice',
6560
));
6661

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

7172
$builder->add('publishedAt', 'date', array(
72-
'input' => 'timestamp',
73-
'widget' => 'choice',
73+
// render as a single text box
74+
'widget' => 'single_text',
7475
));
7576

76-
The field also supports an ``array`` and ``string`` as valid ``input`` option
77-
values.
77+
This will render as an ``input type="date"`` HTML5 field, which means that **some -
78+
but not all - browsers will add nice date picker functionality to the field**. If you
79+
want to be absolutely sure that *every* user has a consistent date picker, use an
80+
external JavaScript library.
81+
82+
For example, suppose you want to use the `Bootstrap Datepicker`_ library. First,
83+
make the following changes::
84+
85+
$builder->add('publishedAt', 'date', array(
86+
'widget' => 'single_text',
87+
88+
// do not render as type="date", to avoid HTML5 date pickers
89+
'html5' => false,
90+
91+
// add a class that can eb selected in JavaScript
92+
'attr' => ['class' => 'js-datepicker'],
93+
));
94+
95+
Assuming you're using jQuery, you can initialize the date picker via:
96+
97+
.. code-block:: html
98+
99+
<script>
100+
$(document).ready(function() {
101+
$('.js-datepicker').datepicker({
102+
format: 'yyyy-mm-dd'
103+
});
104+
});
105+
</script>
106+
107+
This ``format`` key tells the date picker to use the date format that Symfony expects.
108+
This can be tricky: if the date picker is misconfigured, Symfony won't understand
109+
the format and will throw a validation error. You can also configure the format
110+
that Symfony should expect via the `format`_ option.
111+
112+
.. caution::
113+
114+
The string used by a JavaScript date picker to describe its format (e.g. ``yyyy-mm-dd``)
115+
may not match the string that Symfony uses (e.g. ``yyyy-MM-dd``). This is because
116+
different libraries use different formatting rules to describe the date format.
117+
Be aware of this - it can be tricky to make the formats truly match!
78118

79119
Field Options
80120
-------------
@@ -181,3 +221,5 @@ Field Variables
181221
+--------------+------------+----------------------------------------------------------------------+
182222
| date_pattern | ``string`` | A string with the date format to use. |
183223
+--------------+------------+----------------------------------------------------------------------+
224+
225+
.. _`Bootstrap Datepicker`: https://github.com/eternicode/bootstrap-datepicker

0 commit comments

Comments
 (0)