ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.


A first look at the Zend Framework

(Page 4 out of 4)


The Zend_Service components comes with three different API's, for Flickr, Amazon and Yahoo, making it extremely easy to query these web services.

The Zend_Service_Amazon API comes with several methods to query the Amazon web service. For example, to get a list of PHP books, the following code is used:

require_once 'Zend/Service/Amazon.php';
$amazon = new Zend_Service_Amazon('AMAZON_API_KEY&');
$response = $amazon->itemSearch(array('SearchIndex' => 'Books', 'Keywords' => 'php'));
foreach ($response as $r) {
    echo $r->Title .'';

(Please note that the above code requires you to have your own Amazon API KEY).

As you can see in the above example, the framework makes it extremely straightforward to use the Amazon Web Service (AWS), and you don't have to worry about parsing any XML at all. This is all done for you by the framework.

The Amazon API also allows you to connect to the Amazon Web Services from other countries, e.g Japan:

// Connect to Amazon in Japan
require_once 'Zend/Service/Amazon.php';
$amazon = new Zend_Service_Amazon('AMAZON_API_KEY', 'JP');

Check out the manual for the full details on how to use the Amazon API.

Just like the Amazon component, the Flickr component, called Zend_Service_Flickr, makes querying the Flickr web service no problem. For example to get photos tagged with "php":

require_once 'Zend/Service/Flickr.php';

$flickr = new Zend_Service_Flickr('MY_API_KEY');

$results = $flickr->tagSearch("php");

foreach ($results as $result) {
    echo $result->title . '';

(Please note you need an API key for Flickr as well)

Again the Zend Framework makes it so much easier to use the Flickr web service, and you don't have to worry at all about XML parsing, encoding problems or anything else. Have a look at the manual to see what's possible.

Finally there's also the Zend_Service_Yahoo component, which can be used to query Yahoo's search engine web service and find documents, images, news and more. Like the previous two web services, it's really simple to use:

require_once 'Zend/Service/Yahoo.php';
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");
$results = $yahoo->webSearch('PHP');
foreach ($results as $result) {
    echo $result->Title .'';

Or to find images:

require_once 'Zend/Service/Yahoo.php';
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");
$results = $yahoo->imageSearch('PHP');
foreach ($results as $result) {
    echo $result->Title .'';

Have a look at the manual to see exactly what's possible

It's a shame that the framework only supports three web services at the moment, but hopefully more will be added in the future.


In this article I've taken you through a few components of the new Zend Framework, but there's plenty more I haven't shown you, so I highly suggest you download the framework yourself, have a look at the manual, and try out all the different components.

So far I'm quite impressed with the framework. At the moment it still has a few kinks and problems, and it definitely needs some more work, but from what I can tell it really looks like a good piece of work. I can easily see this framework making PHP development much faster, easier and more secure. Let's hope version 1.0 is released soon, and that it gets a lot of support by web hosts and enterprise users.

« Previous: Zend_Feed & Zend_InputFilter

4 Responses to “A first look at the Zend Framework”

  1. tim Says:

    So, compare these four lines:

    $select->from(’round_table’, ‘*’);
    $select->where(’noble_title = ?’, ‘Sir’);

    “SELECT * FROM round_table WHERE noble_title = ‘Sir’ ORDER BY first_name limit 10,20″

    How is the 4 line object statement (copied below) “so much easier” than a single line SQL statement?

    The SQL can be formatted however the user wishes, remaining readable, and happily including variables.

    SELECT * FROM round_table
    WHERE noble_title = ‘Sir’
    ORDER BY first_name
    LIMIT 10,20

    The SQL-way has less typing, reads as an English sentence, both enhancing creation and maintenance. Importantly, the SQL select statement can be made in one string, so errors where a piece of the object has not been updated since a previous call, but the SQL still executes, are not possible.

    For getting the job done, bog-standard PHP still seems to rule for me. My prediction is that the X on X fad will maintain a noisy list of supporters, but the 80% apps that make money, help us discover things, and change the world, are going to remain, like php, simple enough to get the job done, and leave SQL alone to do its lovely specialism.

    I think Andy is right: Scaffolding saves 5 minutes once. Php saves you those minutes every hour for the rest of your coding. It stays out of your way while you work, understanding that no one can do the work for you, least of all a dumb language. Work remains a product of mass acceleration and distance: that makes it fundamentally hard.

  2. Matthijs Says:

    Indeed it will be very interesting to see where this framework will go. I also like the input filtering approach in which the access to the raw data is removed. Marco Tabini wrote about this (or a similar) concept in the feb issue of PHP architect, calling it poka-yoke, which is Japanese for “fail-safe mechanism.”

  3. zbijowski::marcin Says:

    Zend Framework - wejście smoka

    Kilka dni temu została opublikowana pierwsza wersja zapowiadanego od dluższego czasu Zend Framework oznaczona numerkiem 0.1.1. Podszedłem do tego dość sceptycznie i z dystansem, bo publikacja tak wczesnej wersji mogła okazać się niewypałem, a …

  4. Lee Doolan Says:

    Ok, so the argument to fetchAll is a string. So, like,
    $result = $db->fetchAll(”SELECT * FROM round_table WHERE noble_title = ‘Sir’ ORDER BY first_name limit 10,20″)

    does what you want, right?

Leave a Reply

About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.
Article Index
  1. The Zend Framework
  2. Zend_Db
  3. Zend_Feed & Zend_InputFilter
  4. Zend_Service & Conclusion
Bookmark Article
Download Article
Download this article as a PDF file