Original Content

Using Zend_Tool to start up your ZF Project

Note: This article has been updated to reflect the paths to installing Zend_Tool manually via the incubator as of 1/12/09. If you are interested in a non-manual installation via the PEAR installer, please see this blog post for more information. -ralph

This tutorial will set you through using Zend_Tool to jump-start development
on your next ZF MVC application. Zend_Tool is both RAD tools as well as a
framework for exposing your own set of tooling needs to the Zend_Tool user
interface. While the areas in which extending Zend_Tool are exhaustive, we will
focus merely on obtaining and using the current Zend_Tool toolset.

Obtaining Zend_Tool

There are two method one can go about obtaining Zend_Tool. The first method is to
get it from the 1.7 release. Inside this release, you will notice that Zend_Tool
has been shipped inside the /incubator directory. To get this working on your
system, you should simply copy the file from within the /incubator/Zend directory from within
[1.7 release directory]/incubator/library/Zend/Tool/ into your PHP’s
system include_path (specifically into the Zend folder already on your include_path).

The second method of obtaining Zend_Tool (and best method to keep
Zend_Tool up to date
), is to check out the most recent committed version
inside of ZF’s subversion repository. The repository url for the
development version of Zend_Tool is
http://framework.zend.com/svn/framework/standard/incubator/library/Zend/Tool/ and the scripts from http://framework.zend.com/svn/framework/standard/incubator/bin/.

Putting Things in their Proper Place

Once you have Zend_Tool on your system, its time to get them in their
proper locations. For Zend_Tool to work correctly, the Zend Framework
must be installed to your systems include_path. To find your system’s
include_path, check your php.ini file, or use the command line version
of php with the -i switch. Once you have located your include_path,
ensure the Zend directory from the Zend Framework Standard Library is
copied into that include_path. Once you have ZF installed, then get
the Zend_Tool library code installed into the proper location.

If you have obtained Zend_Tool from the release package, then you
should copy [release directory]/incubator/library/Zend/Tool/library/Zend/Tool
into your include_path inside the Zend directory. If you obtained Zend_Tool from the subversion
repository, then you would copy [check out
location]/library/Zend/Tool/
into your include path inside the Zend directory.

Once you have the libraries put into their proper location, there is
only one step left. Included with the Zend_Tool component is also a
command line interface into Zend_Tool. To get this working
seamlessly on your system, you will need to move the proper command
line interface script into your SYSTEM path.

For *Nix based Systems:

For an *nix based system, you should copy the ./bin/zf.sh script into
your system path. To have the script available system wide, this
might be a directory like /usr/bin, or perhaps the same path your php
binary is available. For a local user only installation, most *nix
systems will allow you to create a bin directory inside your home
directory for local path scripts and binaries. In either case, you
should have the php binary available to you as well.

For Win32 based Systems:

For a windows based system, you should copy the ./bin/zf.bat file into
your path. Generally speaking, this script should go into the same
directory as your php.exe application.

Checking things Work

To make sure things work, lets execute a simple command:

This command should show the version of the Zend Framework that is
installed to your systems include_path. If that works, GREAT, its
time to move on. If that doesn’t work, you should start
troubleshooting and making certain that you have done all of the above
mentioned steps.

Creating a Project

Out of the box, Zend_Tool (specifically Zend_Tool_Project) is capable
of creating a working “hello world” application. This project comes
complete with the proper directory structure, an index file, a
bootstrap file, an index and error controller and the corresponding
view scripts. To see this in action, first go ahead and create a
project directory. Next, go ahead and setup your vhost to point to
this project directory, but make sure the document root will be served
out of your Project’s “public” folder. This directory will be created
when you run the project creation script. Restart apache, and ensure
that vhost is working (you should get a forbidden message since the
public directory doesn’t exist yet).

Now its time to create a project. Start up your terminal application
and change to the directory of the project. Inside this projects
directory, execute the following command:

At this point, you should have a fully working project. To test this,
you should be able to go to your web browser and pull up the vhost and
see the text:

Hello from the index view script.

Now you have a fully working project that you can now start building
upon. The directory structure is there and your application has been
bootstrapped.

A Little Extra

Zend_Tool_Project also comes with the ability to be able to create
actions (within existing Action Controllers) and create the
corresponding view scripts as well. That command comes in the
following form:

This will create both the action (method inside the proper controller)
and the view script that will be executed for that action.

This tutorial should give you enough to get started using Zend_Tool to
create your own ZF MVC applications by simply executing a few quick
commands. Please stay tuned as we will explore added functionality of
Zend_Tool as well as how to extend Zend_Tool with custom functionality.

Published: January 13th, 2009 at 4:44
Categories: Tutorials, Zend Framework

48 comments to “Using Zend_Tool to start up your ZF Project”

I am trying to work through this example but running into problems on the command line.

I found that the first time I ran the "zf show version" command I received an error message saying "Could not open input file: C:\php\zf.php" so obviously I copied that to the appropriate directory, I’m sure the instructions in tutorial only mention copying the .bat file.

Also I get the following error message:

PHP Fatal error: Call to undefined method SplFileInfo::getRealPath() in C:\php\
extras\ZendLab\ZendL\Tool\Rpc\Loader\IncludePathLoader.php on line 28

Fatal error: Call to undefined method SplFileInfo::getRealPath() in C:\php\extra
s\ZendLab\ZendL\Tool\Rpc\Loader\IncludePathLoader.php on line 28

The only info I could find on the SplFilInfo class was here http://www.php.net/~helly/classbrowser/class.php?class=SplFileInfo

Like the error suggests, I don’t see a getRealPath method for this class, any ideas where I may have gone wrong?

I got next exception after command `# zf create project`
"Exception: RecursiveDirectoryIterator::__construct(./Zend): failed to open dir: No such file or directory"

There are two foldres created ‘application’ and ‘library’, and one file ‘.zfproject.xml’ only. But there is no public folder with index.php

If you are running into any issues, and want assistance, I have two outlets for help.

The first is mainly for development purposes, discussions on future enhancements and fixes – a yahoo group:

http://tech.groups.yahoo.com/group/zf-tool/

The second is an IRC channel I will be in:

#zf-tool on irc.freenode.net

So if you are having issues, please come find me!

-Ralph

I get the following after running: zf create project

"Exception: RecursiveDirectoryIterator::__construct(./Zend): failed to open dir: No such file or directory"

inside my project folder i have:
‘application’
‘library’
‘.zfproject.xml’

no folder public, no index.php

Been using Zend Framework for about a month, but really wanted cli tools – excellent addition. I got this to demo to work well – now to see what else it can do. great work!

Hello,

ZendL\Tool\Rpc\Endpoint\Abstract.php have two calls to an inexisting exception class (ZendL_Tool_Endpoint_Exception). Change to ZendL_Tool_Rpc_Endpoint_Exception.

This will be a great tool, but for the moment I think have many problems
For example I must set the $zendFrameworkPath and $zendFrameworkLabPath in zf.php and after that when i try to run zf.sh I got this error ,,Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 7680 bytes) in /usr/share/php/Zend/Controller/Response/Abstract.php on line 112”

Works fine here, very nice.
Great job. I wish we could see more articles about this great zend framework module. Things like personalization creation and more.

@orfeu: Hi, I’ve encountered this same error when I first ran the tool. What you should do is to edit your php.ini file, look for the line:

memory_limit = 32M

And change it to:

memory_limit = 128M

Hope this helps,
Crix

Just my thoughts after trying out this nice new feature:

In most real-life (enterprise) projects, the library/Zend directory will either be a symbolic link or an svn:externals property.
Do you think copying it this way into a new project will prove to be useful for those situations?

I’ve try, and I obtain this message :

PHP Warning: Zend_Loader::include_once(ZendL\Tool\Rpc\Endpoint\Cli.php): failed to open stream: No
such file or directory in F:\Program Files\Zend\Core\ZendFramework\library\Zend\Loader.php on line 83

It’s not an include problem because, really, there is not ‘Cli.php’ file in ‘ZendL\Tool\Rpc\Endpoint\’ directory.

Why did it try to reach this file in this place ?

I downloaded the latest ZF (1.6.1) and Zend_Tool from SVN today, but I’m getting the following error:

~/zf/Zend_Tool/library $ zf show version
An error has occured:
Action ‘show’ is not a valid action.

I think that I’ve followed the instructions properly, but here’s my directory setup, just in case:

~/zf/Zend_Tool/library $ php -i | grep include_path
include_path => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc

~/zf/Zend_Tool/library $ l /usr/share/php | grep Zend
lrwxrwxrwx 1 root root 47 Sep 21 12:50 Zend -> /home/davew/zf/ZendFramework-1.6.1/library/Zend/
lrwxrwxrwx 1 root root 38 Sep 21 12:50 ZendL -> /home/davew/zf/Zend_Tool/library/ZendL/
lrwxrwxrwx 1 root root 35 Sep 21 12:52 zf.php -> /home/davew/zf/Zend_Tool/bin/zf.php*
lrwxrwxrwx 1 root root 34 Sep 21 12:53 zf.sh -> /home/davew/zf/Zend_Tool/bin/zf.sh*

~/zf/Zend_Tool/library $ ls -l /usr/share/php/Zend/Loader.php
-rw-r–r– 1 davew advent 8538 Jul 25 23:29 /usr/share/php/Zend/Loader.php

~/zf/Zend_Tool/library $ ls -l /usr/share/php/ZendL/Tool/Rpc/Endpoint/Cli.php
-rw-r–r– 1 davew advent 934 Sep 21 12:32 /usr/share/php/ZendL/Tool/Rpc/Endpoint/Cli.php

~/zf/Zend_Tool/library $ which zf
~/bin/zf

~/zf/Zend_Tool/library $ l ~/bin/zf
lrwxrwxrwx 1 davew advent 34 Sep 21 13:04 /home/davew/bin/zf -> /home/davew/zf/Zend_Tool/bin/zf.sh*

I put some debugging statements in the ZendL/Tool/Rpc/Endpoint/Cli* code and it looks like the _manifests and _metadatas arrays aren’t being populated in ZendL_Tool_Rpc_Manifest_Registry so when ZendL_Tool_Rpc_Endpoint_Cli_GetoptParser::parse() tries to search the list of metadata (line 46), it doesn’t find a match.

Has anyone encountered this problem?

Interesting. I replaced the symlinks with the actual directories/files and now it works:

~ $ zf show version
Zend Framework Version: 1.6.1

~ $ php -i | grep include_path
include_path => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc => .:/usr/share/pear:/usr/share/php:/var/www/html/Common/inc

~ $ l /usr/share/php | grep Zend
drwxr-xr-x 50 davew advent 4096 Sep 14 12:00 Zend/
drwxr-xr-x 8 davew advent 4096 Sep 21 12:32 ZendL/

~ $ l /usr/share/php | grep zf
-rwxr-xr-x 1 davew advent 1584 Sep 21 13:48 zf.php*
-rwxr-xr-x 1 davew advent 1325 Sep 21 13:02 zf.sh*

~ $ l ~/bin/zf
lrwxrwxrwx 1 davew advent 20 Sep 23 20:28 /home/davew/bin/zf -> /usr/share/php/zf.sh*

Any ideas why the symlinks don’t work?

It dosn’t set you up with the same structure as the one used in the quickstart – and there is no db connection example in an ini or anything like that. Ive basicly run the tool and then copied the qucickstart stuff over the top.

Appreciate it absolutly bare bones. But too bare i reckon.

Probably should file a report, but very quickly:

[root@bordel ~]# zf show version
Zend Framework Version: 1.6.1
[root@bordel ~]# zf
PHP Warning: Zend_Loader::include_once(ZendL/Tool/Endpoint/Exception.php): failed to open stream: No such file or directory in /opt/ZendFramework-1.6.1/library/Zend/Loader.php on line 83

Changing ZendL_Tool_Endpoint_Exception to ZendL_Tool_Rpc_Endpoint_Exception in Abstract.php fixes the error.

Nice, thanks :) but imho it’s easy to do it via zend eclipse )

I did everything, but when I write that code: "zf show version", appear that: "zf.php cannot find the Zend Framework Standard Library. Please either set the $zendFrameworkPath in zf.php OR set the ZF_PATH environment variable."

I ask you, what I have to do to resolve the problem.

I’ve made some new step, and now I have this error :
Fatal error: Cannot redeclare class ZendL_Controller_Tool_ActionProvider in F:\Program Files\Zend\Co
re\ZendFramework\laboratory\Zend_Tool\library\ZendL\Controller\Tool\ActionProvider.php on line 37

I’ve to change include path, add framework path into zf.php and so on,

Without success…

I’m on Win XP Pro and I developpe every day without problem with ZF…

Thank you to give more detail to make it work.

In zf.php :
$zendFrameworkPath = ‘F:\\Program Files\\Zend\\Core\\ZendFramework\\library\\Zend’;
$zendFrameworkLabPath = ‘F:\\Program Files\\Zend\\Core\\ZendFramework\\laboratory\\Zend_Tool\\library’;

The ErrorController requires an errorAction() method. Otherwise, you will get an error rather than being redirected to your error page.

I’m on windows and the project file cant be used by Zend Studio for Windows…
I’m desapointed…

i encoutered some troubles while installing/using it but it’s finally working and really fine !
Here are some tips that might help. Under Win XP + WAMP (php5.2.5).

1. copy zf.php in the same dir as php.exe (with zf.bat)
2. edit zf.php file and change relative paths to point to your own "includes/library" directory. Example:
$zendFrameworkPath = dirname(__FILE__) . ‘/../myincludes/library/’;
$zendFrameworkIncPath = dirname(__FILE__) . ‘/../myincludes/library/’;

3. disable the php_domxml.dll extension in the php.ini
(;extension=php_domxml.dll ;comment the line)

After all that, it’s finally working !!! Thanx!

which the meaning of is there the file .zfproject.xml?
How is it works?

_____anonymous_____
January 14th, 2009 at 11:06 am

Could you explain to us what Zend_Tool actually is?

Also "*it’s" time to get them".

I get no output when running the shell script, as in nothing, no errors, no text just nothing.
I don’t have any ZendL directory and have no idea where it comes from.
Of course, I am lost.

Showing the same error.
ZF 1.7.3
PHP Fatal error: Call to undefined method SplFileInfo::getRealPath() in /usr/share/php/Zend/Tool/Framework/Loader/IncludePathLoader.php on line 38

Using ZF 1.7.3, i get the same error others have reported when running zend tool:

PHP Fatal error: Call to undefined method SplFileInfo::getRealPath() in /usr/share/php/Zend/Tool/Framework/Loader/IncludePathLoader.php on line 38

From the php changelog, SplFileInfo::getRealPath() was added in version 5.2.2, so it seems zend tool won’t work with earlier versions.

Note that Zend_Tool will work automagically with ZF-1.7.4. Here are the lines from ZendFramework-1.7.4/incubator/bin/zf.php that make it clear:

/**
* DEV ONLY START – this will be removed when this hits trunk
*/
$zendFrameworkPath = realpath(dirname(__FILE__) . ‘/../../library/’); // trunk
$zendFrameworkIncPath = realpath(dirname(__FILE__) . ‘/../library/’); // incubator

So if you downloaded the full version of ZF-1.7.4, all you need is to create a symlink in your PATH to zf.sh (NO COPYING whatsoever) and you’re clear to go.

Error :(

C:\Documents and Settings\Chris>zf show version

Warning: require_once(Zend/Tool/CodeGenerator/Php/File.php): failed to open stre
am: No such file or directory in C:\wamp\www\zendframework\library\Zend\Tool\Pro
ject\Context\Zf\ControllerFile.php on line 4

Fatal error: require_once(): Failed opening required ‘Zend/Tool/CodeGenerator/Ph
p/File.php’ (include_path=’.;c:\wamp\www\zendframework\library’) in C:\wamp\www\
zendframework\library\Zend\Tool\Project\Context\Zf\ControllerFile.php on line 4
C:\Documents and Settings\Chris>

Did you get Zend_Tool via svn? Because it’s messed up right now. They’re probably doing some major refactoring or someone accidentally svn rm’d the whole CodeGenerator tree because it’s missing in the repository right now. It seems that rev14033 is the last rev where the CodeGenerator was last seen, so add a -r14033 during checkout.

It took me about 5 hours to get this working with ZF 1.7.7, but I eventually got there. In case it helps anyone else, CodeGenerator seems to be missing from the incubator.

After copying the ‘Tools’ directory from the incubator, I had to check out CodeGenerator into the Tools directory using -r 14033 (as mentioned above). I then had to update CodeGenerator/Php/File.php to the latest version (to get new reflection methods available) and change all paths and class names so that they had "Tool" in them.

There must be an easier way to do this (and I’m fairly new to ZF). If anyone wants me to go into more detail I can do that, but it would be great if someone could point out how to do this properly.

How could I get the CodeGenerator/Php/File.php, I m behind firewall, cannot access through svn.

Here’s a summery of what I did. PLEASE feel free to tell me how to do this properly. There must be an easier way!

cd $PATH_TO_ZF/ZendFramework-1.7.7

cp -r incubator/library/Zend/Tool/ library/Zend/

cp -r incubator/library/Zend/Reflection/ library/Zend/

cd library/Zend/Tool

mkdir CodeGenerator

cd CodeGenerator

svn co http://framework.zend.com/svn/framework/standard/incubator/library/Zend/CodeGenerator .

cd ..

find . | grep -v .svn | xargs perl -pi -e "s|Zend/CodeGenerator|Zend/Tool/CodeGenerator|g"

find . | grep -v .svn | xargs perl -pi -e "s|Zend_CodeGenerator|Zend_Tool_CodeGenerator|g"

extension=php_domxml.dll is enabled in php.ini
zf show version is fine, but can’t create project, any idea?

-zf show version
Zend Framework Version: 1.7.2

-zf create project
Creating project at C:\xampp\htdocs\zend\test

Warning: domdocument::domdocument(): Entity: line 1: parser error : Start tag expected, ‘&gt’ not found in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 42

Warning: domdocument::domdocument(): 1.0 in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 42

Warning: domdocument::domdocument(): ^ in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 42

Fatal error: Cannot instantiate interface in C:\xampp\php\PEAR\Zend\Tool\Project\Profile\FileParser\Xml.php on line 44

I too tore my hair out before finally downloading http://framework.zend.com/releases/ZendFramework-1.8.0b1/ZendFramework-1.8.0b1.zip.

Then I ran into a snag regarding "class DOMDocument not found…" This was resolved on my fedora system with

yum install php-xml

and trying again. At that point I got "Class ‘Zend_Controller_Action’ not found…" so I opened zf.php in an editor and added

require("Zend/Loader.php");
Zend_Loader::registerAutoload();

Unless I am doing something wrong, I would hope to see this fixed in the production release.

@cc96ai: As said before, extension=php_domxml.dll must be commented out (*disabled*) in the php.ini, not enabled. ;-)

Hi to all,
I try to use Zend_Tool 1.8.1 to create a controller into new module, but I have some problem.
I did:
$ zf create project prova
$ cd prova
$ zf create module admin
Now, I see new directory "application/modules/admin/" and sub-directory "controllers models views". I try to create a new controller into admin module with:
$ zf create controller index admin
but ZF say me:
—————
An Error Has Occurred
This project already has a controller named index
—————
Can I have a controller name index into new module admin?

Next, I try to create a new controller into module admin with:
$ zf create controller gestione admin
and see:
——————————–
Creating a controller at /Applications/MAMP/mhd/zf/prova/application/controllers/GestioneController.php
Creating an index action method in controller gestione
Creating a view script for the index action method at /Applications/MAMP/mhd/zf/prova/application/views/scripts/gestione/index.phtml
Creating a controller test file at /Applications/MAMP/mhd/zf/prova/tests/application/controllers/GestioneControllerTest.php
Updating project profile ‘/Applications/MAMP/mhd/zf/prova/.zfproject.xml’
——————————–

Why I don’t see the controller "gestione" into module "admin"?

Thank you

@a-alonz, the problem you are having is a bug in Zend_tool.

See http://framework.zend.com/issues/browse/ZF-6755 for more information.

Yes ZF now becoming some what RAD tool like symfony-project. Previously was just a library .

Thanks Ralph for this wonderful tool . Need some good examples to show how this command line works in developing an application . Something like a blog .

Anyway Thanks once again .

Hari K T
http://harikt.com

Hello. I’ve been struggling with ZF CLI for 2 days now, still I can’t get it to work.
I’ve got PHP installed in C:\Program Files\PHP, and ZF resides in C:\Program Files\PHP\includes\library\Zend.
PHP include_path: .;.\includes\library\Zend\Tool
Environment variable ZEND_TOOL_INCLUDE_PATH set up to C:\Program Files\PHP\includes\library\Zend\Tool.
Yet every time I try to execute zf.bat I get the following output:

——————————

Warning: file_exists(): open_basedir restriction in effect. File(C:\Program File
s\PHP/../library/Zend/Tool/Framework/Client/Console.php) is not within the allow
ed path(s): (C:\inetpub\phpsites) in C:\Program Files\PHP\zf.php on line 363

***************************** ZF ERROR ********************************
In order to run the zf command, you need to ensure that Zend Framework
is inside your include_path. There are a variety of ways that you can
ensure that this zf command line tool knows where the Zend Framework
library is on your system, but not all of them can be described here.

The easiest way to get the zf command running is to allow is to give it
the include path via an environment variable ZEND_TOOL_INCLUDE_PATH or
ZEND_TOOL_INCLUDE_PATH_PREPEND with the proper include path to use,
then run the command "zf –setup". This command is designed to create
a storage location for your user, as well as create the zf.ini file
that the zf command will consult in order to run properly on your
system.

Example you would run:

$ ZEND_TOOL_INCLUDE_PATH=/path/to/library zf –setup

Your are encourged to read more in the link that follows.
Zend_Tool & CLI Setup Information
(available via the command line "zf –info")
* Home directory found in environment variable HOMEPATH with value \Users\└фь
шэшёЄЁрЄюЁ
* Home directory does not exist at \Users\└фьшэшёЄЁрЄюЁ
* Home directory found in environment variable USERPROFILE with value C:\User
s\└фьшэшёЄЁрЄюЁ
* Home directory does not exist at C:\Users\└фьшэшёЄЁрЄюЁ

To change the setup of this tool, run: "zf –setup"

——————————

What can I do with it?

Hi man ,
Please change the zf library from the program files and keep it some where else .
Add the include_path fully.. ie if its in d:\zend\library
If you have any trouble its good to install xampp as its coming with zf . Don’t want to go and do I think :)
Else come join hands with LAMP .

Yeah, I have already solved the problem. I moved Zend folder to C:\inetpub\wwwroot, as you said and it works now. Thanks.

Is there a way to make zend tool create an application.xml file instead of an application.ini file? What is the advantage of using one vs the other?

Thanks.

I am using Zend Framework -1.7.2. When I am giving command in Terminal as follows:

root@Sampada:~# zf show version
Zend Framework Version: 1.7.2 It gives correct output.

I am giving another command in Terminal as follows:

root@Sampada:/opt/lampp/htdocs/zend1.7.2# zf create project
creating project at /opt/lampp/htdocs/zend1.7.2.

It is also runing correctly but, it is not actually creating project at that particular location. So I can’t go ahead.

I stuck up with this problem. Please, can anybody help me for this problem.

Thanks

Is the version 1.7 itself ? Or you mean 1.10.7 ?

According to my knowledge the zf tool comes from 1.8 onwards .

Also if there is such a problem you don’t want to be stuck . Create the project structure as you see in the doc .

You have done ;) .

I feel you may not be having the proper permission to create directory . You can check going to the directory and trying to create one with GUI mode or in command line mkdir <dirname>

Let me know what you get .

If you were like me, I was sudo-ing as root when trying to execute the dang zf.sh script. I linked it up from /usr/bin/zf -> /usr/local/lib/php/Zend/bin/zf.sh and I followed all the steps every tutorial gave me, but it DOES NOT WORK when SUDOING!

So if you are retarded like me, and you hire your server staff to look into it, and they wind up charging you $65/hr for logging in as root and typing a command… then please, by all means, save your self the AGONY and just login as root to execute the zf script.

Hope this helps somebody. If it does, hire me: http://www.foundco.com