Posted By

vitor_np on 05/17/11


Tagged

Framework zend


Versions (?)

JSON Zend framework


 / Published in: PHP
 

  1. <?php
  2.  
  3. class IndexController extends Zend_Controller_Action
  4. {
  5.  
  6. public function init()
  7. {
  8. /* Initialize action controller here */
  9. }
  10.  
  11. public function indexAction()
  12. {
  13. $this->getHelper('ViewRenderer')->setNoRender(true);
  14. $values = array('foo' => 'bar');
  15. $this->getHelper('json')->sendJson($values);
  16. }
  17. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: postNuKe on June 8, 2011

I think if you have a AjaxController by example, in the init() you can write this: $this->_helper->AjaxContext()->addActionContext('ajax-handler', 'json')->initContext('json');

Now all data transmitted to the view will be converted into JSON format. This method is preferable to manually turn off the view and convert data to JSON.

Posted By: postNuKe on June 8, 2011

I think if you have a AjaxController by example, in the init() you can write this:

$this->_helper->AjaxContext()->addActionContext('ajax-handler', 'json')->initContext('json');

Now all data transmitted to the view will be converted into JSON format. This method is preferable to manually turn off the view and convert data to JSON.

You need to login to post a comment.