Skip to content

Commit 7af480f

Browse files
authored
Merge pull request #7899 from cakephp/fix-7896
Update ServerRequest::getBody() documentation
2 parents 8cc846e + 129bc7e commit 7af480f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

en/controllers/request-response.rst

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,24 @@ replace all possibly existing uploaded files::
224224
PUT, PATCH or DELETE Data
225225
-------------------------
226226

227-
.. php:method:: input($callback, [$options])
227+
.. php:method:: getBody()
228228
229229
When building REST services, you often accept request data on ``PUT`` and
230230
``DELETE`` requests. Any ``application/x-www-form-urlencoded`` request body data
231-
will automatically be parsed and set to ``$this->data`` for ``PUT`` and
232-
``DELETE`` requests. If you are accepting JSON or XML data, see below for how
233-
you can access those request bodies.
231+
will automatically be parsed and available via ``$request->getData()`` for ``PUT`` and
232+
``DELETE`` requests. If you are accepting JSON or XML data, you can
233+
access the raw data with ``getBody()``::
234234

235-
When accessing the input data, you can decode it with an optional function.
236-
This is useful when interacting with XML or JSON request body content.
237-
Additional parameters for the decoding function can be passed as arguments to
238-
``input()``::
235+
// Get the stream wrapper on the request body
236+
$body = $request->getBody();
239237

240-
$jsonData = $this->request->input('json_decode');
238+
// Get the request body as a string
239+
$bodyString = (string)$request->getBody();
240+
241+
If your requests contain XML or JSON request content, you should consider using
242+
:ref:`body-parser-middleware` to have CakePHP automatically parse those content
243+
types making the parsed data available in ``$request->getData()`` and
244+
``$request->getParsedBody()``.
241245

242246
Environment Variables (from $_SERVER and $_ENV)
243247
-----------------------------------------------
@@ -394,7 +398,7 @@ There are several built-in detectors that you can use:
394398
X-Requested-With = XMLHttpRequest.
395399
* ``is('ssl')`` Check to see whether the request is via SSL.
396400
* ``is('flash')`` Check to see whether the request has a User-Agent of Flash.
397-
* ``is('json')`` Check to see whether the request URL has 'json' extension or the
401+
* ``is('json')`` Check to see whether the request URL has 'json' extension or the
398402
`Accept` header is set to 'application/json'.
399403
* ``is('xml')`` Check to see whether the request URL has 'xml' extension or the `Accept` header is set to
400404
'application/xml' or 'text/xml'.

0 commit comments

Comments
 (0)