Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Rob Allen’s Blog: Returning JSON using the Accept header in ZF2

Rob Allen’s Blog: Returning JSON using the Accept header in ZF2

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).

Source: http://www.phpdeveloper.org/news/17756

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Posted Marzec 30th, 2012 in WEB and PHP Development.

Leave a response: