Wednesday, September 29, 2010

Rendering JSON Data for dojo.data.ItemFileReadStore - Zend Framework

Dojo library has dojo.data.ItemFileReadStore and dojo.data.ItemFileWriteStore which are convenient defaults for a simple data store.

However you still have to generate the JSON data from the server-side application.

Luckily Zend Framework has an utility to render JSON data to match dojo.data format called Zend_Dojo_Data class.

Here's an example usage:

    public function vouchersAction() {             $this->_helper->layout->disableLayout();             $this->_helper->viewRenderer->setNoRender(true);                          $vouchers = Doctrine_Core::getTable('Voucher')->findAll(Doctrine_Core::HYDRATE_ARRAY);             $data = new Zend_Dojo_Data('code', $vouchers, 'title');             header('Content-Type: application/json');             echo $data->toJson();     }

No comments:

Post a Comment