The Zend Framework’s soaring popularity, coupled with the rapid evolution of frameworks both within and without the PHP community, have given the Zend Framework team quite a bit to think about in the 19 months since starting work on version 2.0. The results of their hard work will soon be on display, as Zend Framework 2.0 is slated to be released in 2012.
Version 2.0 seeks to improve upon the current release in a number of ways, focusing on making it easier to get started using the framework, improving performance, and fully embracing the latest PHP language enhancements made available to version 5.3. Additionally, high priority has been given to simplifying the extendibility of the framework, a feature long heralded by competing solutions such as Symfony and Rails.
Although the official release won’t be out for several more months, it never hurts to take an early look at what the future holds for a technology used by countless PHP developers around the globe. In this article I’ll present a meandering introduction to the key version 2.0 features that I find particularly compelling.
The Incremental, Necessary Changes of Zend Framework 2.0
Although version 2 is not backwards-compatible with applications created using 1.X, many of the features you’ve grown accustomed to using remain intact. For instance, the 2.0 CLI behavior is identical to that of its predecessor. In fact, you can see for yourself provided you’ve installed PHP 5.3.1 or newer, which version 2.0 requires. The repository is hosted on GitHub, meaning you can clone the latest version via the git clone
command:
$ git clone https://github.com/zendframework/zf2.git
Once cloned, add the bin
directory to your system path, and the library
path to your PHP include_path
. Next, use the ZF CLI to confirm you’ve upgraded to the 2.0 release:
$ zf show version
Zend Framework Version: 2.0.0dev4
From here, you can begin using ZF 2.0 in the very same fashion as is currently done using the 1.X release, using the ZF CLI to create a new project:
$ zf create project dev.zf2example.com
Creating project at /var/www/dev.zf2app.com
You’ll see that the default project structure is also identical to that found in the 1.X release:
application/
docs/
library/
public/
tests/
This alone should come as a sigh of relief for 1.X developers, because it’s the first indication that version 2.0 does not necessarily present a radical departure from existing conventions. Indeed, as project lead Matthew Weier O’Phinney stated in a 2011 PHPCon talk titled ZF2 Patterns, the goal is to “rewrite only where it makes sense”. The most notable bit of rewriting you’ll encounter is the use of namespaces within the controllers:
$ more application/controllers/IndexController.php
<?php
class IndexController extends ZendControllerAction
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
}
The transition to namespaces improves readability in countless ways. Consider for instance a typical 1.X form model:
class Application_Form_Contact extends Zend_Form
{
...
}
Thanks to namespaces, 2.0 form model skeletons look like this:
namespace ApplicationForm;
class Contact extends ZendFormForm
{
...
}
Improved Module Management
Another notable recent development is a recommendation for a standardized module directory structure. Encouraging the reuse and distribution of modules, defined within a recent IRC meeting as “…a composition of components, templates, assets, controllers, and entities that compose a functional part of an application”, has long struck me as a crucial step towards even greater adoption of the framework, and so I was particularly pleased to see movement regarding this matter.
For those curious to know more about what the module management structures might ultimately look like, see Evan Coury’s ZF2 MVC + Modules Prototype tutorial, which was released ahead of the IRC meeting devoted to this matter but nonetheless closely resembles what appears to be the generally agreed upon structure. Also worth reading is the discussion which ensued following Evan’s tutorial announcement.
Doctrine 2 Integration
Although other 2.0 developments are interesting, without question the one which interests me most is the proposed Doctrine 2 integration. Doctrine is a spectacular ORM and database abstraction layer which greatly reduces the time and effort involved in database integration and maintenance. In fact, my affinity for Doctrine is such that I’ve long used it in conjunction with the Zend Framework 1.X, despite a fairly painful configuration process. If you’re interested in learning more about ZF 1.X / Doctrine 2 integration, see my z2d2 GitHub project.
At the time of this writing the development team was scheduled to discuss Doctrine integration; you can view the meeting agenda here. Also be sure to view the IRC Meetings page, as by the time you read this the meeting will have been held, with various important decisions likely being made as a result (which will be documented in the corresponding IRC log available via the aforementioned link).
Learning More About the Zend Framework 2.0
In addition to keeping tabs on the repository changelog, the Zend Framework mailing list is an indispensable resource for developers seeking to keep tabs on version 2.0 progress. Additionally, project lead Matthew Weier O’Phinney regularly posts updates to the Zend Framework 2 Blog.
Another useful resource is the IRC meeting logs, as they provide valuable insight into what key members of the Zend Framework team are thinking about at that very moment. Although the August 31 meeting log reminded me of the famous Abbott and Costello comedy routine Who’s on First, these logs are generally very useful. You can also optionally participate in upcoming meetings; see the schedule for upcoming meeting agendas.
About the Author
Jason Gilmore is founder of the publishing, training, and consulting firm WJGilmore.com. He is the author of several popular books, including “Easy PHP Websites with the Zend Framework”, “Easy PayPal with PHP”, and “Beginning PHP and MySQL, Fourth Edition”. Follow him on Twitter at @wjgilmore.