Zend Framework Tool Usage With Command Line Tool Support

Zend Framework has a powerful command line tool, and it can be used inside PhpStorm by Command Line Tool Support.

Let’s pass through a simple Zend Framework tutorial. You’ll need having PhpStorm 2.0 and Zend Framework installed on your computer.

First we have to add Zend Framework commands to the tool.

Loading Zend Framework Commands

Choose Settings | Command Line Tool Support and press the “Add” button. Three options are offered. Choose “Zend Framework Tool”:

Choose Zend Framework Tool to add

Then provide the path to its $Zend_Framework_Tool_home$/bin/zf.bat file. The description of Zend Framework Tool commands is loaded and saved in a file inside your project settings. In the Settings dialog box, the description looks as follows:

Zend Framework Tool description in Settings

  • The Tool Path field contains the common part of all framework commands. These common parts are “php  $path_to_symfony$ “ in Symfony or  “$Zend_Framework_Tool_home$/bin/zf.bat” in Zend Framework Tool.
  • A common Tool Path can be annoyingly long, so we provide an Alias, which is a string to be used instead of the full Tool Path.
  • By selecting or clearing the  “Enable” checkbox, you can easily have framework commands included or excluded from tool’s auto completion without deleting the description file.
    Now the Enable checkbox is selected, so Zend Framework Tool commands are provided in auto completion. Press Ctrl +Shift+X or choose Tools | Run Command… and type:
    Zend Framework Tool command list

Using Zend Framework Tool Command Line

Now we’ll create a simple Zend Framework project as it is described in Zend ’s  “Quick start” document.

Creating a Zend Project

Press Ctrl +Shift+X and type “zf create project”:

Create project command

The command has three parameters:

  • Required “path”. We set it to macro $ProjectFileDir$, which stands for the path to the PhpStorm project.
  • Optional “name-of-profile” and “file-of-profile”.

Before the command execution, the framework alias “zf” will be changed to Invoke Path. In our case, it is “C:/Program Files (x86)/Zend/ZendServer/share/ZendFramework/bin/zf.bat”.

Project files are created:

Generated project files

After some server configuration welcome page of the project can be seen:

First test

Creating a Layout

Now create layout:

Enable layout command

Check output:

Toolwindow with "enable layout" output

Then do some additional configuration and check “ZF Quickstart Application” header appeared over the welcome page.

Creating a Model and Database Table

The application needs database, so, let’s configure database adapter with three commands:

  1. zf configure db-adapter ‘adapter=PDO_SQLITE&dbname=APPLICATION_PATH “/../data/db/guestbook.db”‘ production
  2. zf configure db-adapter ‘adapter=PDO_SQLITE&dbname=APPLICATION_PATH “/../data/db/guestbook-testing.db”‘ testing
  3. zf configure db-adapter ‘adapter=PDO_SQLITE&dbname=APPLICATION_PATH “/../data/db/guestbook-dev.db”‘ development

Press Ctrl +Shift+X, copy and paste each command. Check commands output:

Configuring  db adapters

Later, script load.sqlite.php will be created in the tutorial, and you’ll need to execute command

> php scripts/load.sqlite.php –withdata

This also can be done with Command Line Tool Support. Run command:

Run php script

$PhpExecutable$ is a macro,  it changes to the php configured in the project settings when a command is executed. In our case it changes to “C:phpphp.exe”:

Script output

Then db-table is created:

Create db table command

With result:

Create db table output

Then create two models and controller and edit them in the way you did before. Check “guestbook” controller works:

Guestbook application

Creating a Form

Now it`s time to create form and action, and then edit them as provided in tutorial:

Create form command

Congratulations, here’s the result:

Guestbook application, sign action

More about Command Line Tool Support in this tutorial.

This entry was posted in Cool Feature, PhpStorm and tagged , , , . Bookmark the permalink.
  • http://rmcreative.ru/ Sam Dark

    Can I use my own command? Not ZF and not Symfony?

  • Shaverdova Elena

    @Sam Dark
    Yes, using custom framework. Blog post and detailed tutorial will be published soon.

  • http://twitter.com/rafib Rafi

    @Shaverdova: Can’t wait for it.

  • http://alexander.ilyin.eu/ Alexander Ilyin

    Thx for review.

  • http://www.codewithstyle.eu Fabio

    I tried the custom framework, but I don’t find any hint for the xml syntax. In addition to that the the alias seems to be broken, I have to enter the full path to my executable in order to work otherwise I obtain

    Cannot run program “phpcs” (in directory “/Users/fabio/Desktop/work/phpStorm/testProject”): error=2, No such file or directory

  • Shaverdova Elena

    @Sam Dark, @Rafi, @Fabio This tutorial contains detailed information about custom frameworks. Hope it help you.

    @Fabio The idea is that tool path is the full path to your executable, and alias is some short word to make invocation handy. Please, give a look at examples in tutorial.

  • http://www.codewithstyle.eu Fabio

    @Elena thank you for hints about general usage and xml syntax, but the other problem remain. Maybe a bug?

    I understood which is the meaning of alias and full path, the problem is that if I try to add some tool in non standard path result is what I posted.

    To be clear, I use Mac Ports so most of my executables are under /opt/local/bin. If I put /opt/local/bin/phpcs for the Php CodeStyle executable as the full path and phpcs (or any other string) under alias it when I exec Ctrl+Shift+X and write phpcs I obtain the error message above. If I try with a standard command, such as /bin/ls and alias l when I write l in the command box I (correctly) obtain the list of files under my project root.

    Should I file an issue report?

    • Shaverdova Elena

      @Fabio Yes, please, file an issue report.

  • http://www.codewithstyle.eu Fabio
  • mgc

    What does this do that zf at a command line doesn’t?

  • leneshka

    @mgs Nothing, it’s just an interface for zf inside IDE. It provides completion and reminds about command parameters, and allows performing the whole work inside IDE.

  • Mantas

    If i want to use CLI fisrt of all i have to create a project. So i did this. Then i want to use zf tool, but i have already created a new project and when i type “zf create project test” the zf project is created inside the first project and because of this i can’t use other zf tool commands like “zf enable layout”. So how to do that if i create a project using zf tool it is also a project of phpstorm? Because in this tutorial it isn’t said how to do this and in the begininig it even doesn’t tell that i have to create a project first if i want to use CLI? What is the best practise for creating project and ZF projects?

  • http://it-kregi.ru Сергей

    Как то не логично происходит создание zf проекта.
    что бы вызвать консоль нужно сначала создать обычный проект, назовем его test, и из него вызвать консоль и выполнить zf create project test, и получается структура test/test/файлы_проекта, а по идеи и удобству надо test/файлы_проекта

    • leneshka

      You need to create PhpStorm’s project, because IDE always works with projects. Then you need to run just zf create project, without any “test”, and zf project would be created in project root directory, because full path to that folder is implicitly provided to zend framework tool.
      Please write in english, for your question may be useful for other users.

  • http://istreamhd.com Brent Schnarr

    I’m trying to run
    zf configure db-adapter ‘adapter=PDO_SQLITE&dbname=APPLICATION_PATH “/../data/db/guestbook.db”‘ production
    but the command line tool complains that it can’t see the parameters. I then try and type it in manually but it won’t let me enter in any parameters. (it also wont let me enter zf create action sign guestbook)


  • exfromtheleft

    2 Questions bu_ndled with an observation!

    1 – did i miss something or you have to setup the command line tools for every single ZF or Symfony projetct?

    2 – I understand that this IDE doesn’t work without any project created, i do not mind that but is it possible nonetheless to setup some functionnalities across projects, i don’t like to compare, but in netbeans when i setup Zf tools or Librairies it is an IDE wide setting, that i can use everytime i need to create a ZF project?

    Other that this IDe is Great, the GUI can be improved though to be a lil bit more graphic like in the ruby version…

  • sharief

    Is there any tool to generate zend frame code