JsonController.php 544 B

123456789101112131415161718
  1. <?php
  2. //
  3. // JSON Encoding Test
  4. //
  5. class JsonController extends AppController {
  6. // Needed to enable JsonView
  7. // http://book.cakephp.org/2.0/en/views/json-and-xml-views.html#enabling-data-views-in-your-application
  8. public $components = array('RequestHandler');
  9. public function index() {
  10. // Use the CakePHP JSON View
  11. // http://book.cakephp.org/2.0/en/views/json-and-xml-views.html
  12. $this->set('message', "Hello, World!");
  13. $this->set('_serialize', array('message'));
  14. $this->RequestHandler->renderAs($this, 'json');
  15. }
  16. }