OSCON 2006: Understanding ZFramework

    Kevin Yank

    This week, Kevin Yank is reporting from OSCON 2006 in Portland, OR.

    John Coggeshall is a respected name in the PHP world, and works as a technical consultant for Zend, and provided a fast-paced introduction to the Zend Framework as it currently exists in pre-release.

    The Zend Framework (ZFramework for short) is an initiative that aims to build a standard framework for developing web applications in a clean, structured manner, using the object oriented features of PHP5. Although it is still under development, there are relatively stable portions of it that are already quite useful by themselves. For example, the portion of the framework that enables MVC-style application development can be used today.

    The Model-View-Controller (MVC) approach to web application development splits the application into three components: the model, which provides a set of objects that represent the data at the heart of the application (usually, these correspond to database records), the view, which provides HTML templates for communicating the content and state of the application to the user, and the controller, which determines what action(s) to take in response to each request received from the browser.

    Coggeshall demonstrated in code the simple mechanism used by the Zend Framework to implement MVC-style development. Totally configuration-free, the system requires the developer simply to write a set of PHP classes with names of the form someController (e.g. articleController), each of which should have a series of methods with names of the form someAction (e.g. createAction, updateAction, deleteAction), which are mapped by the framework to simple URLs that specify the controller, the action, and some number of parameters (e.g. /article/delete/id/123).

    When it comes to processing user input, the framework provides the Zend_InputFilter class, which lets you safely access the values received from the browser by specifying the type of value you expect to have received. For example, if you want a numeric value, you can ask the input filter to provide the data to you in that format. If the browser happens to have sent something other than a numeric value, the input filter prevents that from being a security issue.

    Coggeshall also demonstrated some of the functionality provided by the search engine that is built into the Zend Framework, which is based on the Apache Lucene search engine, which is popular in the Java world.

    There are a few things not built into the framework as yet, where you have to bring your own solutions. For the view layer, for example, you are free to use whatever templating system you prefer. Coggeshall’s demo made use of the Smarty template engine, although simpler apps can use pure PHP embedded in HTML to output dynamic values.

    Also not yet in the framework is a user authentication system, but Coggeshall effectively demonstrated how you can quickly create a specialized controller class that will perform authentication tasks for the application.

    All up, Coggeshall’s presentation was very information-dense, but possibly too code-heavy for the uninitiated to follow. For a more gentle introduction to the Zend Framework, I’d recommend Chris Shiflett’s introductory article at php|architect.