Output Class¶
The Output class provides functions to output specific data: JSON strings, HTML pages, error messages etc.
Calling the Output Class¶
$Output = $this->Output;
Output JSON Data¶
Shows JSON string:
$data = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
$this->Output->json($data); //output will be string ({"a":1,"b":2,"c":3,"d":4,"e":5})
The first argument is the data to encode. Second argument - bool, if true json encoded string will be outputted using echo() function.
Get JSON string:
$data = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
$json_string = $this->Output->json($data, false); //$json_string will contain string ({"a":1,"b":2,"c":3,"d":4,"e":5})