Note: This article has been updated to reflect the paths to installing Zend_Tool manually via the incubator as of 1/12/09. If you are interested in a non-manual installation via the PEAR installer, please see this blog post for more information. -ralph

This tutorial will set you through using Zend_Tool to jump-start development on your next ZF MVC application. Zend_Tool is both RAD tools as well as a framework for exposing your own set of tooling needs to the Zend_Tool user interface. While the areas in which extending Zend_Tool are exhaustive, we will focus merely on obtaining and using the current Zend_Tool toolset.

Obtaining Zend_Tool

There are two method one can go about obtaining Zend_Tool. The first method is to get it from the 1.7 release. Inside this release, you will notice that Zend_Tool has been shipped inside the /incubator directory. To get this working on your system, you should simply copy the file from within the /incubator/Zend directory from within [1.7 release directory]/incubator/library/Zend/Tool/ into your PHP's system include_path (specifically into the Zend folder already on your include_path).

The second method of obtaining Zend_Tool (and best method to keep Zend_Tool up to date), is to check out the most recent committed version inside of ZF's subversion repository. The repository url for the development version of Zend_Tool is http://framework.zend.com/svn/framework/standard/incubator/library/Zend/Tool/ and the scripts from http://framework.zend.com/svn/framework/standard/incubator/bin/.

Putting Things in their Proper Place

Once you have Zend_Tool on your system, its time to get them in their proper locations. For Zend_Tool to work correctly, the Zend Framework must be installed to your systems include_path. To find your system's include_path, check your php.ini file, or use the command line version of php with the -i switch. Once you have located your include_path, ensure the Zend directory from the Zend Framework Standard Library is copied into that include_path. Once you have ZF installed, then get the Zend_Tool library code installed into the proper location.

If you have obtained Zend_Tool from the release package, then you should copy [release directory]/incubator/library/Zend/Tool/library/Zend/Tool into your include_path inside the Zend directory. If you obtained Zend_Tool from the subversion repository, then you would copy [check out location]/library/Zend/Tool/ into your include path inside the Zend directory.

Once you have the libraries put into their proper location, there is only one step left. Included with the Zend_Tool component is also a command line interface into Zend_Tool. To get this working seamlessly on your system, you will need to move the proper command line interface script into your SYSTEM path.

For *Nix based Systems:

For an *nix based system, you should copy the ./bin/zf.sh script into your system path. To have the script available system wide, this might be a directory like /usr/bin, or perhaps the same path your php binary is available. For a local user only installation, most *nix systems will allow you to create a bin directory inside your home directory for local path scripts and binaries. In either case, you should have the php binary available to you as well.

For Win32 based Systems:

For a windows based system, you should copy the ./bin/zf.bat file into your path. Generally speaking, this script should go into the same directory as your php.exe application.

Checking things Work

To make sure things work, lets execute a simple command:

This command should show the version of the Zend Framework that is installed to your systems include_path. If that works, GREAT, its time to move on. If that doesn't work, you should start troubleshooting and making certain that you have done all of the above mentioned steps.

Creating a Project

Out of the box, Zend_Tool (specifically Zend_Tool_Project) is capable of creating a working "hello world" application. This project comes complete with the proper directory structure, an index file, a bootstrap file, an index and error controller and the corresponding view scripts. To see this in action, first go ahead and create a project directory. Next, go ahead and setup your vhost to point to this project directory, but make sure the document root will be served out of your Project's "public" folder. This directory will be created when you run the project creation script. Restart apache, and ensure that vhost is working (you should get a forbidden message since the public directory doesn't exist yet).

Now its time to create a project. Start up your terminal application and change to the directory of the project. Inside this projects directory, execute the following command:

At this point, you should have a fully working project. To test this, you should be able to go to your web browser and pull up the vhost and see the text:

Hello from the index view script.

Now you have a fully working project that you can now start building upon. The directory structure is there and your application has been bootstrapped.

A Little Extra

Zend_Tool_Project also comes with the ability to be able to create actions (within existing Action Controllers) and create the corresponding view scripts as well. That command comes in the following form:

This will create both the action (method inside the proper controller) and the view script that will be executed for that action.

This tutorial should give you enough to get started using Zend_Tool to create your own ZF MVC applications by simply executing a few quick commands. Please stay tuned as we will explore added functionality of Zend_Tool as well as how to extend Zend_Tool with custom functionality.