Using Zend Tool

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

1
php.ini
’s
1
include_path
, 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
Sites
folder for all my development work so I’m going to check it out there.

svn co http://framework.zend.com/svn/framework/standard/tags/release-1.9.4 ZendFramework

It’s not small, depending on your network, this could take awhile…

Once that’s finished

1
cd
into the
1
ZendFramework
dir and the core library is in
1
library/Zend
, with the Zend Tool scripts in
1
bin/
.

##Add Zend Framework to your Include Path Second step is to add the the contents of the

1
Zend
folder to you include path. I’m using Macports so
1
php.ini
file is located in
1
/opt/local/etc/php5/
. By default the includes path was commented out and looked like this: ;include_path = “.:/php/includes”

Change that to uncomment it and add the

1
library
folder of your checkout

1
include_path = ".:/php/includes:/Users/clint/Sites/ZendFramework/library"

##Setting up the script The

1
bin
folder comes with 3 scripts, a shell script
1
zf.sh
, bat script for Windows users
1
zf.bat
, and a php script that they both use
1
zf.php
.
1
zf.sh
is the script I’ll be using and we need it on our system
1
PATH
, 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

1
zf
into the command-line:

output.jpg

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

test-app-structure.jpg

and view it on the web: http://localhost/test-app/public. You should get the default homepage setup of a Zend Framework Application:

home.jpg

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

1
ToolController
and added view scripts for you under
1
views/scripts/tool/

tool-controller.jpg

You can see the default text for that script here: http://localhost/test-app/public/tool

Now lets create an action. Zend Tool’s

1
create action
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
Index
Controller.

1
zf create action example tool

Your results should be like this:

tool-example-action.jpg

There are other options and methods in Zend Tool; if you’ve made this far and understand, you can figure them out

@ctshryock

About

My name is Clint Shryock. I develop things in Go and Ruby. I live in central Missouri, where the weather is beautiful 4 months of the year.
+-----------------+
|                       |
|      (ノ^_^)ノ      |
|                       |
|   ☜(゚ヮ゚☜)    |
|                       |
|     ౿(ఠ_ఠఎ)    |
|                       |
|        ಠ_ಠ         |
x                      x
  xxx           xxx
       xx    xx
           xx