News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen's Blog:
Returning JSON from a ZF2 controller action
March 29, 2012 @ 08:55:39

In a new post to his blog Rob Allen shows how you can return JSON data directly back from a controller in a Zend Framework 2 application.

The new view layer in Zend Framework 2 can be set up to return JSON rather than rendered HTML relatively easily. [...] Firstly we need to set up the view's JsonStrategy to check to a situation when returning JSON is required and then to render out JSON for us.

This "JsonStrategy" does some of the hard work for you - detecting when the client is requesting a JSON response and looking at the data coming into the view to see if it's JSON. He shows how to implement it in a sample module using the "onBootstrap" module and how to force a return of the JsonModel even when JSON isn't requested (useful for a consistent interface).

0 comments voice your opinion now!
json controller return data jsonmodel viewmodel zendframework2


blog comments powered by Disqus

Similar Posts

The Bakery: Keeping bindModel and unbindModel out of your Controllers

Ibuildings techPortal: Create MVC: Meet the ViewModel Pattern

DevShed: Building a Database-Driven Application with the Code Igniter PHP Framework

Cal Evans' Blog: I called Zend_Json::encode(), so WTH are all my properties?

MaltBlue.com: \Zend\Db\Sql - Creating Joins and Unions with Ease


Community Events











Don't see your event here?
Let us know!


facebook release overview unittest component security performance install composer language hack symfony2 podcast opinion introduction application framework package database hhvm

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework