The Zend Framework: an Introduction

In this second part of a four-part series on the MVC paradigm and the Zend framework, you’ll learn what the framework can help you accomplish and how to install it. This article is excerpted from the chapter 25 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

The Zend Framework

The Zend Framework, an open source project fostered by the prominent PHP product and services provider Zend Technologies ( http://www.zend.com/) was at the time of this writing the most aggressively developed of the four frameworks. Additionally, the Zend Framework provides a variety of task-specific components capable of carrying out tasks that are becoming increasingly commonplace in today’s cutting-edge Web applications. In addition to facilitating MVC-driven development, the Zend Framework can automate CRUD (create, retrieve, update, delete) database operations, and perform data caching and filter input. But what makes the Zend Framework particularly intriguing is the assortment of components it offers for performing nonessential but increasingly commonplace tasks such as creating PDF’s, interacting with the Amazon, Flickr, and Yahoo! APIs, and consuming RSS feeds.

The rest of this chapter is focused on a fast-paced introduction to the Zend Framework’s key features, serving to acquaint you with its usage as well as to excite you about the amazing boost in productivity it and similar frameworks have to offer.

Introducing the Zend Framework

Although all of the frameworks presented in the previous section are very powerful and worthy of further consideration, Zend’s particularly unique approach to framework development led to the decision to explore it further in this chapter. To begin, Table 25-1 summarizes the components available by way of the framework, which should give you a pretty good idea of its diverse set of capabilities. This is followed by an overview of the installation process, and finally two examples. The first example is intended to show you just how easy it is to construct a Web site skeleton using the framework, while the second offers a somewhat more practical twist, using the Yahoo! Web Services component to facilitate sales research.

To begin, take a moment to review Table 25-1, which presents a partial list of the most interesting Zend Framework components accompanied by a brief description. In the two examples found later in this section, you’ll learn how to deploy several of these components.

Table 25-1. A Partial Listing of Zend’s Feature-Specific Components   

Component

Purpose

Zend_Amazon

Facilitates interaction with Amazon E-Commerce Service.

Zend_Cache

Caches data into speedy backend adapters such as RAM, SQLite, and APC (Alternative PHP Cache). 

Zend_Config

Facilitates the management of application configuration parameters.

Zend_Controller

Manages the framework’s controller component.

Table 25-1. A Partial Listing of Zend’s Feature-Specific Components (Continued)   

Component

Purpose

Zend_Db

Drives the framework’s PDO-based database API abstraction layer.

Zend_Feed

Consumes RSS and Atom feeds.

Zend_Filter

Facilitates the filtering and validation of data, including the ability to validate proper syntax for commonplace values such as e-mail addresses, credit card numbers, dates (according to ISO 8601 format), and phone numbers. 

Zend_Filter_Input

Relies upon the methods provided by Zend_Filterto filter input.

Zend_Gdata

Provides an interface to several of Google’s services, including, among

others, Google Blogger, Google Calendar, and Google Notebook.

Zend_HTTP_Client

Performs HTTP requests. Presently capable of executing GET, POST,  PUT, and DELETE requests.

Zend_Json

Facilitates interaction between JavaScript and PHP by serializing PHP data to JSON (JavaScript Object Notation) and vice versa. See http://www.json.org/ 
for more information about JSON.

 

Zend_Log

Facilitates application logging.

Zend_Mail

Sends text and MIME-compliant e-mail.

Zend_Mime

Parses MIME messages.

Zend_Pdf

Creates PDF documents.

Zend_Search_Lucene

Facilitates search engine development using the Lucene library.

Zend_Service_Amazon

Facilitates interaction with the Amazon Web Services API.

Zend_Service_Flickr

Facilitates interaction with the Flickr Web Services API.

Zend_Service_Yahoo

Facilitates interaction with the Yahoo! Web Services API.

Zend_View

Manages the framework’s view component.

Zend_XmlRpc

Provides support for consuming and serving XML-RPC implementations.

 

{mospagebreak title=Downloading and Installing the Zend Framework}

Proceed to http://framework.zend.com/download to download the latest stable version of the Zend Framework. There are three available options for retrieving the source code, including downloading zip and tar packages, or checking out the code from Zend’s Subversion repository. Choose whichever option is most convenient for you, uncompress the code if you choose one of the former options, and move the library directory to a convenient location, within the PHP installation directory’s includes directory, for instance. Only this library directory is relevant, so you can disregard all other files in the uncompressed package. Also, consider changing the library directory name to something very easy to reference, such as zfw.


Caution  The Zend Framework requires PHP 5.1.4 or newer.


Because the Zend Framework works by routing all requests through a single script, you’ll also need to configure Apaches mod_rewrite module. Create an .htaccess file and place the following contents in it, saving the file to the document root:

RewriteEngine on
RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php


Note  Apache’s mod_rewrite module is a powerful feature of Apache used to manipulate requested URLs. On Windows, mod_rewrite is disabled by default. To enable it, you’ll need to open up httpd.conf and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so, update the appropriate AllowOverride directive to allow .htaccess files to be used, and then restart the Apache server. See the Apache documentation for more information about this directive.


Finally, because you’ll need to reference several Zend Framework components from within your application, and it’s always wise to ensure maximum application portability, this directory should be directly accessible by appending it to the php.ini file’s include_path directive. For example, on Linux this directive might look like this:

include_path = ".:/usr/local/lib/php/includes/zfw/"

On Windows this directive might look like this:

include_path = ".;c:phpincludeszfw"

If you don’t have control over the php.ini file, not to worry; you can place the following directive in the .htaccess file, which should reside in the server’s document root:

php_value include_path ".:/usr/local/lib/php/includes/zfw/"

On Windows the directive might look like this:

php_value include_path "C:phpincludeszfw"

The Zend Framework has been configured. If you added the include_path information to php.ini, you’ll need to restart your Web server in order for the changes to take effect.

Please check back next week for the third part of this article.

Google+ Comments

Google+ Comments