How To Use Zend Tool

How To Use Zend Tool

Before I continue this series I thought I would discuss Zend Tool. This came about when Matthew Setter who has an excellent blog on Zend Framework at Master Zend Framework tweeted me after I wrote 'Hello World Part 1' and asked if I ever use the Zend Tool. Though I don't use it as I have my own coding style which I like to have in all my applications, I can see how it can be useful as with the 'Hello World' series I could of done this in one part with a few lines of code. So with that in this article I will show you how to install the Zend Tool and create your first app with it. This tutorial should be good for Linux and Mac.

In 'Installing Zend Framework' we made a 'public' folder change to that directory by cd ~/public.

Install Zend Tool

Now we have to install the Zend Tool by (if you haven't installed Composer see 'Installing Zend Framework')

composer require zendframework/zendtool:dev-maser

This will now install the Zend Tool in our 'public' folder but before we can use it we need to add 'zend-log' to the required libraries as Zend Tool will break with it so edit the '~/public/composer.json' to look like:

    "require": {
        "zendframework/zftool": "dev-master",
        "zendframework/zend-log": "2.*"

Then update composer with composer update.

Now if we run ~/public/vendor/bin/zf.php we should get


Basic information:
  zf.php modules [list]         show loaded modules                                                                                            
  zf.php version | --version    display current Zend Framework version                                                                         

  zf.php diag [options] [module name]    run diagnostics                                                                                       

  [module name]    (Optional) name of module to test                                                                                                                 
  -v --verbose     Display detailed information.                                                                                                                     
  -b --break       Stop testing on first failure                                                                                                                     
  -q --quiet       Do not display any output unless an error occurs.                                                                                                 
  --debug          Display raw debug info from tests.                                                                                                                

Application configuration:
  zf.php config list                  list all configuration options                                                                           
  zf.php config get <name>            display a single config value, i.e. "config get"                                                 
  zf.php config set <name> <value>    set a single config value (use only to change scalar values)                                             

Project creation:
  zf.php create project <path>    create a skeleton application                                                                                

  <path>    The path of the project to be created                                                                                                                    

Module creation:
  zf.php create module <name> [<path>]    create a module                                                                                      

  <name>    The name of the module to be created                                                                                                                     
  <path>    The root path of a ZF2 application where to create the module                                                                                            

Controller creation:
  zf.php create controller <name> <module> [<path>]    create a controller in module                                                           

  <name>      The name of the controller to be created                                                                                                               
  <module>    The module in which the controller should be created                                                                                                   
  <path>      The root path of a ZF2 application where to create the controller                                                                                      

Action creation:
  zf.php create action <name> <controllerName> <module> [<path>]    create an action in a controller                                           

  <name>              The name of the action to be created                                                                                                           
  <controllerName>    The name of the controller in which the action should be created                                                                               
  <module>            The module containing the controller                                                                                                           
  <path>              The root path of a ZF2 application where to create the action                                                                                  

Classmap generator:
  zf.php classmap generate <directory> <classmap file> [--append|-a] [--overwrite|-w]                                                          

  <directory>         The directory to scan for PHP classes (use "." to use current directory)                                                                       
  <classmap file>     File name for generated class map file  or - for standard output. If not supplied, defaults to autoload_classmap.php inside <directory>.       
  --append | -a       Append to classmap file if it exists                                                                                                           
  --overwrite | -w    Whether or not to overwrite existing classmap file                                                                                             

Zend Framework 2 installation:
  zf.php install zf <path> [<version>]                                                                                                         

  <path>       The directory where to install the ZF2 library                                                                                                        
  <version>    The version to install, if not specified uses the last available                                                                                      

Reason for failure: Invalid arguments or no arguments provided

Because we don't want to type ~/public/vendor/bin/zf.php all the time we want to use Zend Tool lets make an alias. So in '~/.bash_profile' file on Mac or '~/.bash_aliases' file on Ubuntu Linux add this line:

alias zftool="~/public/vendor/bin/zf.php"

and then in the terminal type source ~/.bash_profile or source ~/.bash_aliases to active our alias.

Create A Zend Framework Project

Now with that done lets create our new application so in our 'public' folder type zftool create project zf2-tutorial if 'zf2-tutorial' folder also ready exists then use a different one. Once the the Zend Tool has finished cd into our newly created project cd zf2-tutorial since we have just downloaded the Zend Framework Skeleton Application we will need to install all our dependentcies so in our new app folder we type composer install. And that's it!

To prove we have installed our app navigate to it's 'public' folder and typephp -S localhost:8080 ./index.phpto start the PHP test server and in a browser navigate to 'localhost:8080', you should now see:zf2-skeleton-application.png

Now we can use Zend Tool to create our modules, controllers and actions. I will include how to do this in my next article.

Enjoy and love to here your thoughts.


24/07/2014 13:44:00 Shaun Freeman Filed Under: Zend Framework PHP, Zend Framework, Zend Tool, zf2

Twitter Feed
Shaun Freeman @Zendmaster

Shaun Freeman @Zendmaster

I liked a @YouTube video From Carnivore Diet to Near-Death: Lessons Learned From Today's Most Popular Fad Diet

Shaun Freeman @Zendmaster

I liked a @YouTube video Carnivore Diet – Myths about Meat – Phil Escott – WHIS 2018

Shaun Freeman @Zendmaster


Shaun Freeman @Zendmaster

I liked a @YouTube video Dr. Paul Mason - 'Low Carb from a Doctor's perspective'

Shaun Freeman @Zendmaster

I added a video to a @YouTube playlist It's Already Too Late - Elon Musk