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
, 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
folder for all my development work so I’m going to check it out there.
It’s not small, depending on your network, this could take awhile…
Once that’s finished
dir and the core library is in
, with the Zend Tool scripts in
##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
file is located in
. By default the includes path was commented out and looked like this:
;include_path = “.:/php/includes”
Change that to uncomment it and add the
folder of your checkout
1 include_path = ".:/php/includes:/Users/clint/Sites/ZendFramework/library"
##Setting up the script
folder comes with 3 scripts, a shell script
, bat script for Windows users
, and a php script that they both use
is the script I’ll be using and we need it on our system
, which I’m going to do via symbolic link
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:
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
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
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 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