 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Matthew Weier O'Phinney's Blog: Responding to Different Content Types in RESTful ZF Apps
by Chris Cornutt March 05, 2010 @ 12:20:22
Continuing on from his previous articles on working with REST in Zend Framework applications (and making the endpoints for a web service) Matthew Weier O'Phinney has a new tutorial with the next logical step in the series, automatically responding to different content types in your application based on the content-type the client sends.
There's no reason you can't re-use your RESTful web service to support multiple formats. Zend Framework and PHP have plenty of tools to assist you in responding to different format requests, so don't limit yourself. With a small amount of work, you can make your controllers format agnostic, and ensure that you respond appropriately to different requests.
He talks about concerns you'll have to worry about when developing your service - grabbing teh raw input instead of the POST values (since most requests will be rawly POSTed) and what to pass that message to to decode it properly. In his example the Zend_Json and Zend_Config_Xml components make it simpler to handle the info and some code to get the results back into your script.
There's also some code for the other side of things - building the response and pushing it out to the correct views depending on the request content type, action and information.
voice your opinion now!
zendframework rest webservice contenttype json xml tutorial
Lorna Mitchell's Blog: PHP and JSON
by Chris Cornutt February 11, 2010 @ 10:55:06
Lorna Mitchell has taken a look at using JSON in PHP applications in a new post to her blog. More specifically, she looks at how to get it working and a downfall or two that comes with it.
This is a quick outline on working with JSON from PHP, which is actually pretty simple to do. This post has some examples on how to do it and what the results should look like. JSON stands for JavaScript Object Notation, and is widely used in many languages (not just JavaScript) for serialisation. It is particularly popular for use in web services.
She gives an example of the translation between a PHP array (of subarrays) out into a JSON message complete with grouping. She does mention one problem that using this data format has, though - the lack of typing information that comes along with the message details. That can mean the difference between an array being pushed in on the sending side and an object (from json_decode) coming out the other side. As noted in the comments, though, there's a second parameter for json_decode that tells it to force the output as an array instead (along with a mention of another helpful constant in PHP 5.3 - JSON_FORCE_OBJECT).
voice your opinion now!
json example object array webservice
Internet.com: Passing Data Between PHP and JavaScript Using JSON (Video)
by Chris Cornutt February 08, 2010 @ 10:51:42
As Developer.com mentions in a new article, there's a new video tutorial posted over on Internet.com about using PHP and JSON to pass around data in your applications.
Got seven minutes to learn how you can harness the power of PHP, JavaScript and JSON in a powerful AJAX-driven web application? This Internet.com Video tutorial shows you all you need to know to pass data between the client and server using JSON data format.
The video explains a bit about JSON+PHP and shows you how to send a simple message (book-related data) to the server and how to handle the response with a little help from jQuery's Ajax functions.
voice your opinion now!
json jquery tutorial video
Lorna Mitchell's Blog: PHPUnit with Zend_Controller_Action_Helper
by Chris Cornutt July 23, 2009 @ 07:50:20
Lorna Mitchell has posted about another aspect of the REST project she's been developing and an issue that's come up with testing with PHPUnit.
I ran into problems very quickly - when I tried to write the first unit test for the first action in fact! PHPUnit was just dying when I asked it to dispatch() any URL which didn't return HTML, it wasn't even giving its usual output. What was actually happening was I was making use of Zend_Controller_Action_Helper_Json, my service returns JSON and this action helper takes input, transforms it into JSON, sets the content-type correctly and tells ZF not to look for a view since we don't need one. I thought this was pretty neat.
As it turns out, there was an exit being called in the Zend_Controller_Action_Helper_Json component that was causing the request to stop at a certain point. The solution? Chaning the value of the supressExit class variable to stop the behavior.
voice your opinion now!
json action helper zendframework unittest phpunit
Pablo Viquez's Blog: JSON, ISO 8859-1 and UTF-8 - Part
by Chris Cornutt July 20, 2009 @ 12:42:36
After spotting some null values in a few of his form fields following an Ajax request, Pablo Viquez decided to track down his issue:
While I was looking at some AJAX calls, I started to have a problem, for some reason, when I tried to query a JSON service I did using JQuery, the result was null for some fields. Going a little deeper, I notice that the records from the DB were OK, and the JavaScript was OK to, so what was the problem? The JSON Encode!
His issue stemmed from the character encoding of the string being passed into json_encode (in this case, UTF-8) was coming from a PHP script saved in a page encoded as ISO-8859-1. You can download the files he's come up with to illustrate the point.
voice your opinion now!
json encode utf8 iso88591 jsonencode
NETTUTS.com: Create a Twitter-Like "Load More" Widget
by Chris Cornutt July 17, 2009 @ 13:19:26
On NETTUTS.com there's a new tutorial they've created showing the development of a "load more" component for your page combining PHP, MySQL and a javascript library (like Mootools or jQuery).
Both Twitter and the Apple App Store use a brilliant technique for loading more information; you click the link and fresh items magically appear on the screen. This tutorial teaches you to use AJAX, CSS, Javascript, JSON, PHP, and HTML to create that magic. This tutorial will also feature both jQuery and MooTools versions of the script.
The idea is that, after the initial load of the page, the user can click on the "load more" link/button and the Ajax request will get the latest results from the backend (via json messaging). The complete code is available for download and you can check out the demo if you'd like to see it in action.
voice your opinion now!
mootools jquery tutorial json ajax
Rich Buggy's Blog: Dynamic forms using Zend_Form
by Chris Cornutt June 24, 2009 @ 12:05:24
Rich Buggy has posted a new tutorial to his blog looking at the Zend_Form component of the Zend Framework and how you can have it cooperate with the generation of more dynamic forms.
While most forms contain fixed fields there are occasions when you need a form to be dynamic and adjust itself based on user input. The adjustment could be as simple as altering the options in a drop down list or as complex as adding/removing fields. In this post I'm going to cover how to create a dynamic form using Zend_Form and jQuery. I'll use the example of a registration form that prompts the user for their country and state.
He extends the Zend_Form component to make his own registration form with two fields - country and state. Combined with the jQuery code to pull in the JSON formatted state information, the form updates the States list as the country is selected. Complete code is provided.
voice your opinion now!
json jquery zendform zendframework
EasyPHPWebsites.com: Gluing jQuery and PHP Together with JSON
by Chris Cornutt June 24, 2009 @ 10:28:22
The EasyPHPWebsites site has posted the next tutorial in their series looking at combining PHP and Ajax to make more powerful applications. In this new article they look at the combination of PHP and jQuery as connected by JSON messages.
The ability to create powerful Web interfaces using AJAX is accomplished thanks to the marrying of a server-side language such as PHP and the client-side JavaScript language. But how is data passed between a script executing on the server and another executing within the user's browser, all without going through the usual request-response process which requires the page to reload?
The jQuery/JSON "glue" is one alternative and the option he explores. He briefly introduces JSON and its format before getting into the jQuery use of it or the PHP code behind it. Thankfully, PHP has a handy function to make things easier for the developer - the json_encode and json_decode functions.
voice your opinion now!
tutorial json jquery
ITNewb.com: Introduction to JSON and PHP
by Chris Cornutt May 15, 2009 @ 10:24:20
On the ITNewb.com site there's a recent tutorial posted covering the use of JSON in PHP applications - on both the creating and parsing sides.
So you've heard the fanfare over JSON, but still haven't had the opportunity to dive into using it. Well, as a matter of fact, you may have been using JSON all along and not known it. Compounded by the fact that since PHP 5.2 there is native support for JSON, learning how to send data between your client and your server just got a whole lot easier.
He starts off with a look at what JSON is and some examples of the syntax. For his examples he uses the Twitter API's JSON output format to get tweets from a user's timeline. The json_encode and json_decode functions are used on the PHP side to handle the "heavy lifting".
voice your opinion now!
javascript tutorial json introduction
|
Community Events
Don't see your event here? Let us know!
|