How do I handle json data sent as an HTTP Post to a cakephp app?
if($this->RequestHandler->requestedWith('json')) {
if(function_exists('json_decode')) {
$jsonData = json_decode(utf8_encode(trim(file_get_contents('php://input'))), true);
}
if(!is_null($jsonData) and $jsonData !== false) {
$this->data = $jsonData;
}
}
This is a codesnippet which was proposed to be in the core, see https://trac.cakephp.org/ticket/6125. Maybe it's what you're looking for.
-- Bjorn
You can use these simplest way :
$data = $this->request->input ( 'json_decode', true) ;