Zend Tool is a powerful command-line script to help generate Zend Framework “units” as I call them, from the complete initial application structure to controllers, or actions in controllers that already exist.
Though released a the incubator a few versions back, I’ve found it to be more stable and easier to setup just recently. Fortunately I just did a clean install and lost my setup of Zend Tool, giving me the chance to blog about it here.
I first learned how to setup Zend Tool with this guide. It details at least two ways to get Zend Tool running, plus some instructions for Windows users. My instructions will be for Mac OS X (but should work for most Unix-like systems) and for development purposes only.
##Getting Zend Framework
First step is getting the framework. Zend Tool requires the Zend Framework be in your
’s 1
php.ini
, so you need to obtain the source. The Zend Framework source is available for public checkout via subversion, and since you’re developer, we’ll go that route. Personally, I like to checkout a release tag and not a trunk, that way I can incrementally update from tag to tag instead of just updating from the trunk. Either should work. I use my user’s 1
include_path
folder for all my development work so I’m going to check it out there.1
Sites
It’s not small, depending on your network, this could take awhile…
Once that’s finished
into the 1
cd
dir and the core library is in 1
ZendFramework
, with the Zend Tool scripts in 1
library/Zend
.1
bin/
##Add Zend Framework to your Include Path
Second step is to add the the contents of the
folder to you include path. I’m using Macports so 1
Zend
file is located in 1
php.ini
. By default the includes path was commented out and looked like this:
;include_path = “.:/php/includes”1
/opt/local/etc/php5/
Change that to uncomment it and add the
folder of your checkout1
library
1
include_path = ".:/php/includes:/Users/clint/Sites/ZendFramework/library"
##Setting up the script
The
folder comes with 3 scripts, a shell script 1
bin
, bat script for Windows users 1
zf.sh
, and a php script that they both use 1
zf.bat
. 1
zf.php
is the script I’ll be using and we need it on our system 1
zf.sh
, which I’m going to do via symbolic link1
PATH
1
sudo ln -s ~/Sites/ZendFramework/bin/zf.sh /usr/bin/zf
##Using Zend Tool
Check to see if Zend Tool is working by typing
into the command-line:1
zf
The first thing you’ll see is an error, since we didn’t supply the correct number of arguments, but following that you’ll get usage instructions for all the options of Zend Tool.
Now lets create a project by switching to your local server’s document root and running :
1
zf create project test-app
Now take a look around at what was made by opening 1
test-app
and view it on the web: http://localhost/test-app/public. You should get the default homepage setup of a Zend Framework Application:
Zend Tool can do more than just create the project structure, so lets create a controller and an additional action.
1
2
cd test-app
zf create controller tool
You can see that Zend Tool created a controller named
and added view scripts for you under 1
ToolController
1
views/scripts/tool/
You can see the default text for that script here: http://localhost/test-app/public/tool
Now lets create an action. Zend Tool’s
method takes requires a controller name as the second arguement; if you don’t specify one, it will assume you want to use the 1
create action
Controller.1
Index
1
zf create action example tool
Your results should be like this:
There are other options and methods in Zend Tool; if you’ve made this far and understand, you can figure them out