ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

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

Advertisements

A first look at the Zend Framework

(Page 1 out of 4)

Introduction

Last October, Zend, the company behind PHP, announced the PHP Collaboration Project, whereby an Enterprise Level framework will be developed called the Zend Framework. A few days ago, on March 3rd, a preview version of the framework has been released, and it contains some very some interesting components.

In this article we'll have a look at what the framework has to offer, and why you should or should not use it in your PHP scripts. Please note that the Zend Framework requires PHP 5.

What the framework has to offer

The framework comes with several components, which together can handle most of the common PHP tasks. An extensive list can be found on the download page, but here's a short listing of all the current components:

- Zend_Controller and Zend_View (used for controllers, views)
- Zend_Db (database related)
- Zend_Feed (consumes RSS and Atom feeds)
- Zend_HttpClient (provides a client for the HTTP protocol)
- Zend_InputFilter (used to handle raw input data)
- Zend_Json (converts PHP structures into JSON)
- Zend_Log (logs data)
- Zend_Pdf (create PDF files without the need for extensions)
- Zend_Search_Lucene (adds a site search)
- Zend_Service: Flickr, Yahoo and Amazon (provides tools to query these web services)
- Zend_XmlRpc (a XML-RPC library)

Let's go through each component, and see what it can do, and how it works.

Zend_Controller and Zend_View

These two components actually form the basis of a simple MVC framework, and consist of a Front Controller which dispatches requests to page controllers. It's a simple implementation, and Zend is actually working on making it even simpler.

Unfortunately, documentation for these components is virtually non-existent, but it's fairly easy to read the framework source to learn how it works. Full instructions on how to set it up can be found at http://wiki.cc/php/Zend_Controller.

There is one (major) problem with the MVC framework though. The framework expects your index.php to be in your document root, just like Ruby on Rails. For example, you can't run your Zend framework from http://localhost/framework/, but instead you must run it from http://localhost. In the linked setup instructions I gave you above you are shown how to setup a separate virtual host for the framework, but this isn't always possible, especially not on shared hosting.

Maybe this will be fixed in the future, but until then you can find instructions at http://www.akrabat.com/2006/03/04/zend-framework-front-controller/ on how to fix this, although it does make the framework a little less elegant, as it involves writing your own dispatcher.

Let's have a look at the database component.

Next: Zend_Db »



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->order(’first_name’);
    $select->limit(10,20);

    “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
PDF
Download this article as a PDF file