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.

Comments
I found that the first time I ran the "zf show version" command I received an error message saying "Could not open input file: C:\php\zf.php" so obviously I copied that to the appropriate directory, I'm sure the instructions in tutorial only mention copying the .bat file.
Also I get the following error message:
PHP Fatal error: Call to undefined method SplFileInfo::getRealPath() in C:\php\
extras\ZendLab\ZendL\Tool\Rpc\Loader\IncludePathLoader.php on line 28
Fatal error: Call to undefined method SplFileInfo::getRealPath() in C:\php\extra
s\ZendLab\ZendL\Tool\Rpc\Loader\IncludePathLoader.php on line 28
The only info I could find on the SplFilInfo class was here http://www.php.net/~helly/classbrowser/class.php?class=SplFileInfo
Like the error suggests, I don't see a getRealPath method for this class, any ideas where I may have gone wrong?
"Exception: RecursiveDirectoryIterator::__construct(./Zend): failed to open dir: No such file or directory"
There are two foldres created 'application' and 'library', and one file '.zfproject.xml' only. But there is no public folder with index.php
"Exception: RecursiveDirectoryIterator::__construct(./Zend): failed to open dir: No such file or directory"
inside my project folder i have:
'application'
'library'
'.zfproject.xml'
no folder public, no index.php
ZendL\Tool\Rpc\Endpoint\Abstract.php have two calls to an inexisting exception class (ZendL_Tool_Endpoint_Exception). Change to ZendL_Tool_Rpc_Endpoint_Exception.
For example I must set the $zendFrameworkPath and $zendFrameworkLabPath in zf.php and after that when i try to run zf.sh I got this error ,,Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 7680 bytes) in /usr/share/php/Zend/Controller/Response/Abstract.php on line 112''
Great job. I wish we could see more articles about this great zend framework module. Things like personalization creation and more.
memory_limit = 32M
And change it to:
memory_limit = 128M
Hope this helps,
Crix
In most real-life (enterprise) projects, the library/Zend directory will either be a symbolic link or an svn:externals property.
Do you think copying it this way into a new project will prove to be useful for those situations?
PHP Warning: Zend_Loader::include_once(ZendL\Tool\Rpc\Endpoint\Cli.php): failed to open stream: No
such file or directory in F:\Program Files\Zend\Core\ZendFramework\library\Zend\Loader.php on line 83
It's not an include problem because, really, there is not 'Cli.php' file in 'ZendL\Tool\Rpc\Endpoint\' directory.
Why did it try to reach this file in this place ?
~/zf/Zend_Tool/library $ zf show version
An error has occured:
Action 'show' is not a valid action.
I think that I've followed the instructions properly, but here's my directory setup, just in case:
~/zf/Zend_Tool/library $ php -i | grep include_path
include_path => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc
~/zf/Zend_Tool/library $ l /usr/share/php | grep Zend
lrwxrwxrwx 1 root root 47 Sep 21 12:50 Zend -> /home/davew/zf/ZendFramework-1.6.1/library/Zend/
lrwxrwxrwx 1 root root 38 Sep 21 12:50 ZendL -> /home/davew/zf/Zend_Tool/library/ZendL/
lrwxrwxrwx 1 root root 35 Sep 21 12:52 zf.php -> /home/davew/zf/Zend_Tool/bin/zf.php*
lrwxrwxrwx 1 root root 34 Sep 21 12:53 zf.sh -> /home/davew/zf/Zend_Tool/bin/zf.sh*
~/zf/Zend_Tool/library $ ls -l /usr/share/php/Zend/Loader.php
-rw-r--r-- 1 davew advent 8538 Jul 25 23:29 /usr/share/php/Zend/Loader.php
~/zf/Zend_Tool/library $ ls -l /usr/share/php/ZendL/Tool/Rpc/Endpoint/Cli.php
-rw-r--r-- 1 davew advent 934 Sep 21 12:32 /usr/share/php/ZendL/Tool/Rpc/Endpoint/Cli.php
~/zf/Zend_Tool/library $ which zf
~/bin/zf
~/zf/Zend_Tool/library $ l ~/bin/zf
lrwxrwxrwx 1 davew advent 34 Sep 21 13:04 /home/davew/bin/zf -> /home/davew/zf/Zend_Tool/bin/zf.sh*
I put some debugging statements in the ZendL/Tool/Rpc/Endpoint/Cli* code and it looks like the _manifests and _metadatas arrays aren't being populated in ZendL_Tool_Rpc_Manifest_Registry so when ZendL_Tool_Rpc_Endpoint_Cli_GetoptParser::parse() tries to search the list of metadata (line 46), it doesn't find a match.
Has anyone encountered this problem?
~ $ zf show version
Zend Framework Version: 1.6.1
~ $ php -i | grep include_path
include_path => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc
~ $ l /usr/share/php | grep Zend
drwxr-xr-x 50 davew advent 4096 Sep 14 12:00 Zend/
drwxr-xr-x 8 davew advent 4096 Sep 21 12:32 ZendL/
~ $ l /usr/share/php | grep zf
-rwxr-xr-x 1 davew advent 1584 Sep 21 13:48 zf.php*
-rwxr-xr-x 1 davew advent 1325 Sep 21 13:02 zf.sh*
~ $ l ~/bin/zf
lrwxrwxrwx 1 davew advent 20 Sep 23 20:28 /home/davew/bin/zf -> /usr/share/php/zf.sh*
Any ideas why the symlinks don't work?
Appreciate it absolutly bare bones. But too bare i reckon.
[root@bordel ~]# zf show version
Zend Framework Version: 1.6.1
[root@bordel ~]# zf
PHP Warning: Zend_Loader::include_once(ZendL/Tool/Endpoint/Exception.php): failed to open stream: No such file or directory in /opt/ZendFramework-1.6.1/library/Zend/Loader.php on line 83
Changing ZendL_Tool_Endpoint_Exception to ZendL_Tool_Rpc_Endpoint_Exception in Abstract.php fixes the error.
I ask you, what I have to do to resolve the problem.
Fatal error: Cannot redeclare class ZendL_Controller_Tool_ActionProvider in F:\Program Files\Zend\Co
re\ZendFramework\laboratory\Zend_Tool\library\ZendL\Controller\Tool\ActionProvider.php on line 37
I've to change include path, add framework path into zf.php and so on,
Without success...
I'm on Win XP Pro and I developpe every day without problem with ZF...
Thank you to give more detail to make it work.
$zendFrameworkPath = 'F:\\Program Files\\Zend\\Core\\ZendFramework\\library\\Zend';
$zendFrameworkLabPath = 'F:\\Program Files\\Zend\\Core\\ZendFramework\\laboratory\\Zend_Tool\\library';
I'm desapointed...
Here are some tips that might help. Under Win XP + WAMP (php5.2.5).
1. copy zf.php in the same dir as php.exe (with zf.bat)
2. edit zf.php file and change relative paths to point to your own "includes/library" directory. Example:
$zendFrameworkPath = dirname(__FILE__) . '/../myincludes/library/';
$zendFrameworkIncPath = dirname(__FILE__) . '/../myincludes/library/';
3. disable the php_domxml.dll extension in the php.ini
(;extension=php_domxml.dll ;comment the line)
After all that, it's finally working !!! Thanx!
How is it works?
Also "*it's" time to get them".
I don't have any ZendL directory and have no idea where it comes from.
Of course, I am lost.
ZF 1.7.3
PHP Fatal error: Call to undefined method SplFileInfo::getRealPath() in /usr/share/php/Zend/Tool/Framework/Loader/IncludePathLoader.php on line 38
PHP Fatal error: Call to undefined method SplFileInfo::getRealPath() in /usr/share/php/Zend/Tool/Framework/Loader/IncludePathLoader.php on line 38
From the php changelog, SplFileInfo::getRealPath() was added in version 5.2.2, so it seems zend tool won't work with earlier versions.
/**
* DEV ONLY START - this will be removed when this hits trunk
*/
$zendFrameworkPath = realpath(dirname(__FILE__) . '/../../library/'); // trunk
$zendFrameworkIncPath = realpath(dirname(__FILE__) . '/../library/'); // incubator
So if you downloaded the full version of ZF-1.7.4, all you need is to create a symlink in your PATH to zf.sh (NO COPYING whatsoever) and you're clear to go.
C:\Documents and Settings\Chris>zf show version
Warning: require_once(Zend/Tool/CodeGenerator/Php/File.php): failed to open stre
am: No such file or directory in C:\wamp\www\zendframework\library\Zend\Tool\Pro
ject\Context\Zf\ControllerFile.php on line 4
Fatal error: require_once(): Failed opening required 'Zend/Tool/CodeGenerator/Ph
p/File.php' (include_path='.;c:\wamp\www\zendframework\library') in C:\wamp\www\
zendframework\library\Zend\Tool\Project\Context\Zf\ControllerFile.php on line 4
C:\Documents and Settings\Chris>
After copying the 'Tools' directory from the incubator, I had to check out CodeGenerator into the Tools directory using -r 14033 (as mentioned above). I then had to update CodeGenerator/Php/File.php to the latest version (to get new reflection methods available) and change all paths and class names so that they had "Tool" in them.
There must be an easier way to do this (and I'm fairly new to ZF). If anyone wants me to go into more detail I can do that, but it would be great if someone could point out how to do this properly.
http://framework.zend.com/svn/framework/standard/incubator/library/Zend/CodeGenerator/Php/File.php
cd $PATH_TO_ZF/ZendFramework-1.7.7
cp -r incubator/library/Zend/Tool/ library/Zend/
cp -r incubator/library/Zend/Reflection/ library/Zend/
cd library/Zend/Tool
mkdir CodeGenerator
cd CodeGenerator
svn co http://framework.zend.com/svn/framework/standard/incubator/library/Zend/CodeGenerator .
cd ..
find . | grep -v .svn | xargs perl -pi -e "s|Zend/CodeGenerator|Zend/Tool/CodeGenerator|g"
find . | grep -v .svn | xargs perl -pi -e "s|Zend_CodeGenerator|Zend_Tool_CodeGenerator|g"
zf show version is fine, but can't create project, any idea?
-zf show version
Zend Framework Version: 1.7.2
-zf create project
Creating project at C:\xampp\htdocs\zend\test
Warning: domdocument::domdocument(): Entity: line 1: parser error : Start tag expected, '>' not found in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 42
Warning: domdocument::domdocument(): 1.0 in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 42
Warning: domdocument::domdocument(): ^ in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 42
Fatal error: Cannot instantiate interface in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 44
Then I ran into a snag regarding "class DOMDocument not found..." This was resolved on my fedora system with
yum install php-xml
and trying again. At that point I got "Class 'Zend_Controller_Action' not found..." so I opened zf.php in an editor and added
require("Zend/Loader.php");
Zend_Loader::registerAutoload();
Unless I am doing something wrong, I would hope to see this fixed in the production release.
I try to use Zend_Tool 1.8.1 to create a controller into new module, but I have some problem.
I did:
$ zf create project prova
$ cd prova
$ zf create module admin
Now, I see new directory "application/modules/admin/" and sub-directory "controllers models views". I try to create a new controller into admin module with:
$ zf create controller index admin
but ZF say me:
---------------
An Error Has Occurred
This project already has a controller named index
---------------
Can I have a controller name index into new module admin?
Next, I try to create a new controller into module admin with:
$ zf create controller gestione admin
and see:
--------------------------------
Creating a controller at /Applications/MAMP/mhd/zf/prova/application/controllers/GestioneController.php
Creating an index action method in controller gestione
Creating a view script for the index action method at /Applications/MAMP/mhd/zf/prova/application/views/scripts/gestione/index.phtml
Creating a controller test file at /Applications/MAMP/mhd/zf/prova/tests/application/controllers/GestioneControllerTest.php
Updating project profile '/Applications/MAMP/mhd/zf/prova/.zfproject.xml'
--------------------------------
Why I don't see the controller "gestione" into module "admin"?
Thank you
See http://framework.zend.com/issues/browse/ZF-6755 for more information.