Using ZFTool for Basic Project Management

In today’s tutorial, we go through the key options in ZFTool, the tooling support available in Zend Framework 2. We install it, create a basic ZF2 application and more.

Level: Beginner

Duration: 20 mins


Welcome to another tutorial. Today, I will be giving you a walk through of zftool, which provides basic tooling support in Zend Framework 2. If you’re new to Zend Framework, or have been reading the introductory series here, it can come in quite handy.

But unlike other frameworks, such as Yii (through yiic) and Symfony (via the Command Line tool), the tooling support in Zend Framework 2 is rather light on.

These respective tools provide rather robust support for automatically generating models from database connections, checking logs and a host of other much required functionality.

I understand from some tweets with Enrico Zimuel new additions are planned for zftool. But for right now, Zend Framework is definitely the junior. However, that aside, I like to take the adage of a glass half full and see zftool as a good start. Today we’re going to use it to carry out the following tasks:

  1. Create a basic ZF2 project
  2. Create several modules
  3. Creating an autoloader classmap
  4. Checking if there are any issues

By the end of today’s tutorial, you will have a good understanding of how to get started with it and to be able to use it in your projects. Firstly, let’s install zftool and get started.


There are a number of ways in which zftool can be installed, including using Composer and downloading the Phar tool.

During the research for this article, I tried to install it via Composer, but continuously met with permission related errors. As a result, I’ve chosen to focus on the Phar tool approach, which works, almost, seamlessly.

If you’d like to go down the Composer route, run the following command in your Terminal or console and you’ll have it available.

Otherwise, download the phar file. Once it’s downloaded, run the following commands. These make it accessible universally on your system:

If you’re not familiar with the Linux command line, what we’ve done here is to copy zftool.phar to one of the directories automatically in a users PATH.

Then we’ve created a symlink to it, giving it a simpler name and finally set the executable bit on it - now it’s ready to run.

Running the Phar Tool

Now that we have the Phar file available, let’s have a look at the options available. Running the following command will display a help screen, showing all of the options supported:

It will result in output similar to that below:

Creating a Project

Ok, with the tool ready to go, let’s set about using some of it’s functionality to creating and managing a Zend Framework 2 project, as outlined above.

Create the Project

Firstly, we’ll create a raw project, called &‘simple project’. To do so, run the following command:

This will create the core project files in a directory in the current directory, called &‘simpleproject’. It will give you output similar to that below:

Assuming there were no permission issues, the project directory should look as follows:

The Generated composer.json File

Looking in the project directory, we see a new composer.json file, which has the basic configuration and requirements for a Zend Framework 2 project. If you’d like to go further, feel free to alter it as suits your needs, running composer update afterwards.

Installing Zend Framework 2 in the Project (With Composer)

With the basic files in place, unless you have the Zend Framework libraries on your path, the application won’t run. So, in the project directory, run composer.phar install to bring in the required libraries and dependencies.

The output will look similar to that below. I’ve trimmed it for sakes of readability.

Creating a Module

Now we’ve got the base project and dependencies, let’s create a module. We’ll call it “application”.

NB: I believe case is not important; so Application = application.

To create it, run the following command, from your project directory:

Running it, however, returns output listing a series of mkdir errors. I believe this came about as the Application module was already there. If so, it would be helpful to print out a simple message indicating this, instead of attempting to proceed with creating an existing module.

Creating Another Module

Ok, now let’s create a module which doesn’t already exist; we’ll call it Generic. As before, we create the module via the command below:

You should see output similar to that below, indicating there were no problems.

Looking in the Generic module directory, we see the following structure:

Under config is a module.config.php file. So, we now have the basic structure of a ZF2 module.

Viewing a List of Modules

But what if we want to see the list of modules? Well, here’s where I hit an issue. I believe the following command will show us that list.

But no matter what I tried, it always resulted in the following error:

At this stage, I’m not sure if it’s a bug or a user (me) problem. However, as I get more information, I’ll update the post about this issue.

Classmap Generation

Ok, we’re just about done. If you’re familiar with Zend Framework 2, you’ll know that performance can be increased through a classmap file.

A class map file stores a map of files which the application may require, saving it from performing a file location resolution. Effectively, it’s a class file location cache.

Let’s assume we have a series of classes in the module directory. Let’s create a classmap file for it. To do so, we run the following command:

You might also be interested in...

comments powered by Disqus


Buy Mezzio Essentials. Learn the fundamentals that you need, to begin building applications with the Mezzio framework today! Buy Now

Latest YouTube Video

Learn how to write SQL queries in PhpStorm