A first look at the Zend Framework(Page 1 out of 4)
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.