Skip to content

Commit

Permalink
Add docs for cakephp/cakephp#17743
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 2, 2024
1 parent efd13fa commit 733cbaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions en/appendices/5-1-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ I18n

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

TestSuite
---------
Expand Down
10 changes: 9 additions & 1 deletion en/controllers/request-response.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ data and other input::
use function Cake\Core\toBool;
use function Cake\Core\toInt;
use function Cake\Core\toString;
use function Cake\I18n\toDate;
use function Cake\I18n\toDateTime;

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

// Parse a date based on the format or null
$date = toDate($this->request->getQuery('date'), 'Y-m-d');

// Parse a datetime based on a format or null
$date = toDateTime($this->request->getQuery('datetime'), 'Y-m-d H:i:s');

.. versionadded:: 5.1.0
Casting functions were added.

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

0 comments on commit 733cbaa

Please sign in to comment.