Skip to content

Commit 733cbaa

Browse files
committed
Add docs for cakephp/cakephp#17743
1 parent efd13fa commit 733cbaa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

en/appendices/5-1-migration-guide.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ I18n
125125

126126
- ``Number::formatter()`` and ``currency()`` now accept a ``roundingMode``
127127
option to override how rounding is done.
128+
- The ``toDate``, and ``toDateTime`` functions were added. They give you
129+
a typesafe way to cast request data or other input and return ``null`` when
130+
conversion fails.
128131

129132
TestSuite
130133
---------

en/controllers/request-response.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ data and other input::
106106
use function Cake\Core\toBool;
107107
use function Cake\Core\toInt;
108108
use function Cake\Core\toString;
109+
use function Cake\I18n\toDate;
110+
use function Cake\I18n\toDateTime;
109111

110112
// $active is bool|null.
111113
$active = toBool($this->request->getQuery('active'));
@@ -116,6 +118,12 @@ data and other input::
116118
// $query is string|null.
117119
$query = toString($this->request->getQuery('query'));
118120

121+
// Parse a date based on the format or null
122+
$date = toDate($this->request->getQuery('date'), 'Y-m-d');
123+
124+
// Parse a datetime based on a format or null
125+
$date = toDateTime($this->request->getQuery('datetime'), 'Y-m-d H:i:s');
126+
119127
.. versionadded:: 5.1.0
120128
Casting functions were added.
121129

@@ -413,7 +421,7 @@ There are several built-in detectors that you can use:
413421
X-Requested-With = XMLHttpRequest.
414422
* ``is('ssl')`` Check to see whether the request is via SSL.
415423
* ``is('flash')`` Check to see whether the request has a User-Agent of Flash.
416-
* ``is('json')`` Check to see whether the request URL has 'json' extension or the
424+
* ``is('json')`` Check to see whether the request URL has 'json' extension or the
417425
`Accept` header is set to 'application/json'.
418426
* ``is('xml')`` Check to see whether the request URL has 'xml' extension or the `Accept` header is set to
419427
'application/xml' or 'text/xml'.

0 commit comments

Comments
 (0)