News 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 using the Accept header in ZF2
March 30, 2012 @ 08:01:56

In a previous post Rob Allen showed how to return JSON data from a controller in a Zend Framework 2 application. In this new post he shows how to use the "Accepts" header from the client to do the same thing.

Following yesterday's article on returning JSON from a ZF2 controller action, Lukas suggested that I should also demonstrate how to use the Accept header to get JSON. So this is how you do it!

You'll need to create the JsonStrategy first, then you can return the ViewModel from the controller. If all goes well, you should see the sample HTML page rendered in a browser and JSON output when requested with the right "Accept" header (he uses curl in his example).

0 comments voice your opinion now!
json return zendframework2 tutorial jsonstrategy accepts


blog comments powered by Disqus

Similar Posts

Maggie Nelson's Blog: NTILE() - easy way to generate tag clouds

DevShed: Inserting Comments and Accessing Nodes with the DOM XML Extension in PHP 5

ParanoidFerret.com: Using Flex, PHP, and JSON to Modify a MySQL Database

Web Development Blog: Ajax requests using jQuery and PHP

Matthew Leverton\'s Blog: How to add a custom CAPTCHA to phpBB2


Community Events

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


application voicesoftheelephpant library podcast introduction framework community symfony2 interview laravel opinion example conference series performance release version api php7 extension

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