Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions en/appendices/5-1-upgrade-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Console

- ``Arguments::getBooleanOption()`` and ``Arguments::getMultipleOption()`` were added.

Core
----

- The ``toString``, ``toInt``, ``toBool`` functions were added. They give you
a typesafe way to cast request data or other input and return ``null`` when conversion fails.

Http
----

Expand Down
19 changes: 19 additions & 0 deletions en/controllers/request-response.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ If you want to access all the query parameters you can use

$query = $this->request->getQueryParams();

You can use the casting utility functions to provide typesafe access to request
data and other input::

use function Cake\Core\toBool;
use function Cake\Core\toInt;
use function Cake\Core\toString;

// $active is bool|null.
$active = toBool($this->request->getQuery('active'));

// $page is int|null.
$page = toInt($this->request->getQuery('page'));

// $query is string|null.
$query = toString($this->request->getQuery('query'));

.. versionadded:: 5.1.0
Casting functions were added.

Request Body Data
-----------------

Expand Down