 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Rob Allen's Blog: Returning JSON from a ZF2 controller action
by Chris Cornutt 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).
voice your opinion now!
json controller return data jsonmodel viewmodel zendframework2
Konr Ness' Blog: Zend_Config Benchmark - JSON, Array, INI, XML, YAML
by Chris Cornutt March 08, 2012 @ 11:51:32
In this recent post to his blog, Konr Ness has benchmarked the components that the Zend Framework uses to read in different types of configuration files - JSON, native PHP arrays, INI, XML and YAML files.
If you application relies on parsing one or several config files each time it is bootstrapped it is important that you select a file format that is fast to parse. But you also want to select a config file format that is easy for a human to read and edit. In a recent application I am building I also had the need to write modifications to config files, so I also benchmarked the Zend_Config_Writer components.
He includes both the sample configuration INI file and the benchmarking script he used to measure the results (all configurations were read from external files, even the native PHP option). His results were pretty predictable (with the exception of YAML reading) with the standard INI file coming in second to the native PHP arrays, but having the advantage of being more readable.
voice your opinion now!
zendconfig zendframework benchmark json array ini xml yaml
Lorna Mitchell's Blog: Building A RESTful PHP Server Output Handlers
by Chris Cornutt February 01, 2012 @ 10:25:33
Lorna Mitchell is back with another post in her "Building a RESTful PHP Server" series today with this new post showing how to work with output handlers (her focus is on JSON).
So far we've covered parsing requests to determine exactly what the user is asking for, and also looked at routing to a controller to obtain the data or perform the action required. This post gives examples of how to return the data to the client in a good way.
She advocates using output handlers instead of the usual views you'd think of in a typical MVCish sort of application. The difference here is that there's not a lot of extra overhead to produce the results - it's literally an output directly from a class extending the base view (including the correct headers). She also briefly mentions the inclusion of JSONP functionality, allowing you to specify a local callback to execute when the request is returned. A few other "nice to haves" are also mentioned like the number of results returned and pagination support.
voice your opinion now!
output handler restful server json jsonp tutorial view
PHPMaster.com: Targeted Geolocation with Geonames
by Chris Cornutt December 13, 2011 @ 12:10:02
New on PHPMaster.com there's a tutorial from Lukas White about targeting users using geolocation based on the Geonames web service and a latitude/longitude. His example makes a call to find the closest "place" to the given coordinates.
Location-aware applications rely on being able to locate where you are, and this is what geolocation is all about. After all, once the application knows your location, it can go on to find the nearest store, guide you through the appropriate route to a destination, or target relevant advertisements to you. Geolocation, then, is simply the mechanism for identifying your geographical location.
He mentions two challenges associated with geolocation - finding where someone is and describing the location. With Geonames, he shows how to call the service's "findNearbyPlaceName" method to find the closest "place" to a given latitude/longitude combination. Included is a bit of sample PHP to connect to the service and Javascript to request the user's current location.
voice your opinion now!
geolocation tutorial geonames webservice json location
Lorna Mitchell's Blog: POSTing JSON Data With PHP cURL
by Chris Cornutt November 22, 2011 @ 18:06:48
On her blog today Lorna Mitchell has a quick tip for anyone having an issue sending POSTed JSON data with the curl functionality that can be built into PHP. The trick to her method is sending things with the right header.
We can't send post fields, because we want to send JSON, not pretend to be a form (the merits of an API which accepts POST requests with data in form-format is an interesting debate). Instead, we create the correct JSON data, set that as the body of the POST request, and also set the headers correctly so that the server that receives this request will understand what we sent.
She includes a code example (about ten lines) showing the POSTing process that sets up options using curl's curl_setopt. Be sure to set up the headers to send as "application/json" - that's the trick to letting the remote end know the format.
voice your opinion now!
post data tutorial json curl curlsetopt
ZendCasts.com: Building a JSON End-Point With SLIM and jQuery Part 2
by Chris Cornutt November 09, 2011 @ 10:04:00
On ZendCasts.com today there's a new screencast in their "Building a JSON endpoint with the Slim microframework" series - part two focusing on jQuery integration. (Part one is here)
[This screencast is] part 2 in a series on building a JSON end-point. We're using simple RESTful verbage to grab a list of names from a session store.
You'll need to have the base scripts created in part one to follow along effectively. He picks up right where the previous part ends, creating a new view that uses some simple javascript (jQuery) code to pull the "names" values from his simple JSON endpoint. Also included is an example of a form for adding a new name to the list. The full source for the example can be found over on github.
voice your opinion now!
json endpoint tutorial screencasts slim microframework
SitePoint.com: How to Create an XML to JSON Proxy Server in PHP
by Chris Cornutt October 19, 2011 @ 13:07:08
On SitePoint.com today there's a new post from Craig Buckler showing you how to create a simple XML to JSON proxy server in PHP with a SimpleXML object at its heart.
Unless you're new to this web development lark, you'll know the 'X' in 'AJAX' stands for XML - eXtensible Markup Language. But you're probably not using XML. If you are, you'd probably prefer not to. All the cool kids are using JSON or JSON-P: it has a smaller payload, is easier to use and faster to process. [...] Fortunately, there are a couple of solutions which allow you to retain the benefits of XML data interchange but provide the ease of JSON in JavaScript. In this article, we're going to create an XML to JSON proxy server in PHP.
Of course, this will only work with well-formatted XML documents, but it's a quick little hack that pulls in the XML data with a curl request and parses it via SimpleXML and uses json_encode to push it back out as JSON.
voice your opinion now!
xml translate json proxy server tutorial simplexml
|
Community Events
Don't see your event here? Let us know!
|