Note: this article does not refer to the released version of Zend Framework 2!.
If you want to play with the development versions of Zend Framework 2.0, then it's handy to be able to create ZF2 projects using the Zend\Tool command line tool.
Rather unhelpfully, ZF2's Zend\Tool uses the same ini file (~/.zf.ini) as ZF1's Zend_Tool and the same zf.sh script filename, so you can't just put zf2 on to your path and it'll all just work.
I am assuming that you're like me and have production sites using ZF1, so you probably don't want to mess up your current zf.sh usage. This is how I implemented side-by-side ZF cli scripts.
1. Install ZF2 somewhere
I like to install in /usr/local/include. From the command line type:
cd /usr/local/include
git clone git://git.zendframework.com/zf.git zf2
Don't forget to periodically update it with:
cd /usr/local/include
git pull origin master
(And don't be surprised when it breaks whatever you've already coded in ZF2.dev!)
2. Create .zf2.ini
You need an ini file for ZF2, so call it .zf2.ini and store it in your home directory next to .zf.ini. You need to set the correct include path so that Zend\Tool's zf.php can find your ZF2 installation. From the command line type:
echo 'php.include_path = "/usr/local/include/zf2/library:/usr/local/include/Akrabat/zf2/"' >> ~/.zf2.ini
This creates the .zf2.ini file with the correct include_path set up.
3. Create a zf2 alias
Update your ~/.bash_profile to set up an alias to the ZF2 zf.sh script.
Using a text edit, add this line to the end of ~/.bash_profile:
alias zf2='export ZF_CONFIG_FILE=~/.zf2.ini; /usr/local/include/zf2/bin/zf.sh'
Restart your terminal or type source ~/.bash_profile
Now you can type zf2 to run ZF2's zf.sh and Zend\Tool will run and not be affected by any ZF1 configurations you may have!




October 18th, 2010 at 10:48 #
Hi Rob
Very useful post, thanks.
But why are different paths to ZF2 at the second and third step?
'/www/zend-framework/zf2/bin/' - this is a symlink to '/usr/local/include/zf2/'?
October 18th, 2010 at 10:55 #
Hi Oleg,
I actually have two copies of ZF2 on my computer... I've updated the article to be consistent :)
Regards,
Rob...
October 18th, 2010 at 11:06 #
I thought that there is no difference of content of these two paths, but decided to clarify.
Thanks for the explanation
December 18th, 2010 at 13:42 #
Anyway I can checkout latest ZF2 on Windows using Subversion?
For Doctrine2 I can use:
svn co http://svn.github.com/doctrine/doctrine2.git doctrine2-orm
Tried:
svn co http://git.zendframework.com/zf.git zf2
But no cigar! Google also draws a blank.
Thx
June 21st, 2011 at 16:51 #
Hi Rob,
I set this op in my home folder, but when I try to use the zf2 command, eg. zf2 create project zf2test i get the following error:
Fatal error: Cannot redeclare class Zend\Tool\Project\Provider\Project in /Users/johan/zf2/library/Zend/Tool/Project/Provider/Project.php on line 241
July 13th, 2011 at 10:20 #
@johan I have the same problem. It's look like that Zend\Tool ain't ready for use yet
July 15th, 2011 at 17:36 #
@johan @sasquatch
I had the same problem. But I downloaded today the last version by Git, and there is still a problem, but different :
When I now run "zf2 create project foo", I have a zf.sh error :
An Error Has Occurred
"projectDirectory" was supplied but no profile file file was not found
at location /.zfproject.xml
July 15th, 2011 at 18:02 #
I would tend to agree with sasquatch that ZF2's Zend\Tool is a work in progress...
July 17th, 2011 at 16:32 #
I've tried with zf.sh v1 to create the project, and just replaced the old classes with the new, with namespaces - Zend_Application with Zend\Application\Application, Zend_Controller_Action with Zend\Controller\Action, Zend_Application_Bootstrap_Bootstrap with Zend\Application\Bootstrap. It worked for me.