News Feed
Sections




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

Jason Fox:
Use the Accept Header to Set Your Return Data With Zend Framework 2
February 22, 2013 @ 11:42:35

Jason Fox has a recent post to his site about using "Accept" headers in Zend Framework 2 apps to set the format of the return data from a request.

In this article I detail the process by which you can set up your controller actions in Zend Framework 2 to return either the default HTML, or JSON data depending on the "Accept Header" in the request. It incorporates changes related to a security update added since this very helpful article was written, and expands on some of the intricacies of making your web layer objects better "json providers."

His example uses a "ViewJsonStrategy" and the criteria to look for to determine which version to respond with (HTML or JSON) - the Accept header. It uses the JSON encoder/decoder instead of the built-in PHP one to he could use the included "toJson" method to customize the output of the JSON instead of just returning everything.

0 comments voice your opinion now!
accept http header zendframework2 tutorial json


blog comments powered by Disqus

Similar Posts

Rafael Dohms' Blog: Deploying a Symfony2 and Composer app on PagodaBox

Gonzalo Ayuso's Blog: Speed up page page load combining javascript files with PHP

NetTuts.com: Aspect-Oriented Programming in PHP with Go!

Elizabeth Smith's Blog: How to Compile PHP5.2 and PHP-GTK2 on Windows using Visual C++ Express

WorkingSoftware.com.au: Configuring PHP4 and PHP5 to run concurrently on FreeBSD


Community Events

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


voicesoftheelephpant example api podcast opinion security version framework php7 community laravel introduction laravel5 interview release list library language extension series

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