Home

How to use zendtool in Zend Framework 2

Leave a comment

Here is step by step guide to create a module in a zend framework 2 application using zendtool.

Step A. First Install zendtool

Step 1: First Download the Zend Tool from here. Secondly, extract the files into your root (www) localhost folder and rename the folder to anything you want. I will call it “zftool. So zendtool path look like this – C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zftool

This file provides you with all the necessary files to create your basic folder structure.

Step 2: Download the zftool.phar from packages.zendframework.com

And copy it to zendtool folder.

Step 3: Open your Terminal. (In Windows 7, click Start and in the search box type “cmd” (no quotes), and click cmd.exe.

Step 4: Once opened, use the “cd” command to navigate to the folder where you created your project in your root (www) localhost folder. My command looks like this “cd C:\Program Files\php_5_4_15_Win32_VC9_x86\www″. You should be inside the root folder now and your line in Terminal should resemble this “C:\Program Files\php_5_4_15_Win32_VC9_x86\www>″.

Step 5: Now type this command, “php zftool/zftool.phar version” and press Enter, To check zendtool. For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www>php zftool/zftool.phar version

Output look like bellow:

ZFTool – Zend Framework 2 command line Tool

The ZFTool is using Zend Framework 2.2.0

This means zendtool install and working fine.

Step B. use zendtool

Step 1. Assumtions

Zendframework 2 project created with zf2 installed.

Path like this

http docs root path:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www

zf2 project / application path:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www\ZendSkeletonApplication6ACLNAV

Step 2. Use zendtool to create module in zf2 application

Here is how you can user zendtool on zf2 application for creating a module

Step a: Open your Terminal. (In Windows 7, click Start and in the search box type “cmd” (no quotes), and click cmd.exe.

Step b: Once opened, use the “cd” command to navigate to the folder where you created your project in your root (www) localhost folder. My command looks like this “cd C:\Program Files\php_5_4_15_Win32_VC9_x86\www″. You should be inside the root folder now and your line in Terminal should resemble this “C:\Program Files\php_5_4_15_Win32_VC9_x86\www>″.

Step c: Now type this command, “php zftool/zftool.phar create module user ZendSkeletonApplication6ACLNAV” and press Enter, To use zendtool. For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www> php zftool/zftool.phar create module user ZendSkeletonApplication6ACLNAV

Output look like bellow:

The module User has been created in ZendSkeletonApplication6ACLNAV

 

This means zendtool install and working fine.

 

Similarly other commands of zendtool can be used in zf2 application.

References:

1.)    https://maheshvnit.wordpress.com/2013/06/10/zend-framework-2-how-to-create-a-new-project-how-to-install-skeleton-application/

2.)    http://framework.zend.com/manual/2.2/en/modules/zendtool.introduction.html

2.)    https://github.com/zendframework/ZFTool

Zend Framework 2 – How to Create A New Project / How to install Skeleton Application

12 Comments

ZF2 There has been lots of confusion with new Zend Framework 2 lately. The manual on Zend Framework‘s website is horrible (in terms of beginner manual and documentation) and is designed for advanced user’s with Zend Framework 1 extensive experience.

Many users are still unable to create a first basic folder structure to begin using Zend Framework 2 library. The initial example is provided here. I’m going to break it down for you guys.

(Note: This instruction guide assumes you have successfully installed Apache web server and PHP 5.3 or above)

Method 1: by downloading skeleton application

Step 1: First Download the Zend Framework Skeleton Application from here. Secondly, extract the files into your root (www) localhost folder and rename the folder to anything you want. I will call it “zf_project1”.path look like this – C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1
This file provides you with all the necessary files to create your basic folder structure.

Step 2: Open your Terminal. (In Windows 7, click Start and in the search box type “cmd” (no quotes), and click cmd.exe.

Step 3: Once opened, use the “cd” command to navigate to the folder where you extracted your zip file you downloaded in step 1 (“zf_project1”). My command looks like this “cd C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1″. You should be inside the folder now and your line in Terminal should resemble this “C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1>

Step 4: Now type this command, “php composer.phar self-update” and press Enter.

For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1>php composer.phar self-update

Output look like bellow:

Updating to version f56b985884b1631dbcbc675434ead96168462824.

Downloading: 100%

Step 5: Type another command, “php composer.phar install”. This will create your directories for basic skeleton application.

For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1>php composer.phar install

Output look like bellow:

Loading composer repositories with package information

Installing dependencies (including require-dev)

– Installing zendframework/zendframework (2.2.0)

Loading from cache

zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features (included in default builds of PHP))

zendframework/zendframework suggests installing doctrine/annotations (Doctrine Annotations >=1.0 for annotation features)

zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback random byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavailable)

zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyManager to handle lazy initialization of services)

zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)

zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form)

Writing lock file

Generating autoload files

That’s all. Now, open your browser and navigate to your localhost and zf_project1/public folder (mine looks like this: http://localhost/zf_project1/public/). You should see this website. If you do, then every step has been successfully completed.

Method 2: by using zendtool

Step 1: First Download the Zend Tool from here. Secondly, extract the files into your root (www) localhost folder and rename the folder to anything you want. I will call it “zendtool. So zendtool path look like this – C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zendtool

This file provides you with all the necessary files to create your basic folder structure.

Step 2: Download the zftool.phar from packages.zendframework.com

And copy it to zendtool folder.

Step 3: Open your Terminal. (In Windows 7, click Start and in the search box type “cmd” (no quotes), and click cmd.exe.

Step 4: Once opened, use the “cd” command to navigate to the folder where you created your project in your root (www) localhost folder. My command looks like this “cd C:\Program Files\php_5_4_15_Win32_VC9_x86\www″. You should be inside the root folder now and your line in Terminal should resemble this “C:\Program Files\php_5_4_15_Win32_VC9_x86\www>″.

Step 5: Now type this command, “php zendtool/zftool.phar version” and press Enter, To check zendtool. For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www>php zendtool/zftool.phar version

Output look like bellow:

ZFTool – Zend Framework 2 command line Tool

The ZFTool is using Zend Framework 2.2.0

This means zendtool install and working fine.

Step 6: Now type this command,”php zendtool/zftool.phar create project zf_project1” and press enter, to create project “zf_project1”. For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www>php zendtool/zftool.phar create project zf_project1

Output look like bellow:

ZF2 skeleton application installed in zf_project1.

In order to execute the skeleton application you need to install the ZF2 library.

Execute: “composer.phar install” in zftest

For more info in zftest/README.md

 

Step 7: Now use the “cd” command to navigate to the project. My command looks like this “cd zf_project1

C:\Program Files\php_5_4_15_Win32_VC9_x86\www>cd zf_project1

Now you should be inside the project folder and your line in Terminal should resemble this “C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1>″.

Step 8: Now type this command, “php composer.phar self-update” and press Enter.

For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www\ zf_project1>php composer.phar self-update

Output look like bellow:

Updating to version 1a7f734bc78df99553a742dfac6651a4863c00c6.

Downloading: 100%

Step 9: Now type this command, “php composer.phar install” and press Enter.

For me look like this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www\ zf_project1>php composer.phar install

Output look like bellow:

Loading composer repositories with package information

Installing dependencies (including require-dev)

– Installing zendframework/zendframework (2.2.0)

Loading from cache

zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features (included in default builds of PHP))

zendframework/zendframework suggests installing doctrine/annotations (Doctrine Annotations >=1.0 for annotation features)

zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback random byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavailable)

zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyManager to handle lazy initialization of services)

zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)

zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form)

Writing lock file

Generating autoload files

That’s all. Now, open your browser and navigate to your localhost and zf_project1/public folder (mine looks like this: http://localhost/zf_project1/public/). You should see this website. If you do, then every step has been successfully completed.

References:

1.)    http://framework.zend.com/manual/2.2/en/user-guide/overview.html

2.)    http://framework.zend.com/manual/2.2/en/user-guide/skeleton-application.html

3.)    https://github.com/zendframework/ZFTool/

4.)    http://framework.zend.com/manual/2.2/en/modules/zendtool.introduction.html

Update 1 – 12-06-3013

if you see this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1>php composer.phar install
Composer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP 5.3.1, upgrading is strongly
recommended.
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
– The requested package php >=5.3.3 could not be found.
Problem 2
– zendframework/zendframework 2.2.0rc3 requires php >=5.3.3 -> no matching package found.
– zendframework/zendframework 2.2.0rc2 requires php >=5.3.3 -> no matching package found.
– zendframework/zendframework 2.2.0 requires php >=5.3.3 -> no matching package found.
– Installation request for zendframework/zendframework >2.2.0rc1 -> satisfiable by zendframework/zendframework[2.2.0, 2.2.0rc2, 2.2.0r
c3].

Potential causes:
– A typo in the package name
– The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion&gt; for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md&gt; for further common problems.

This means PHP version not appropriate, you must have 5.3.3 or above.

So now first upgrade php:

download your desired version of php binary from http://windows.php.net/download/ website. download Thread Safe binary zip version. Unzip the downloaded version of the PHP in a separate folder. Please make sure that your new php folder name is not “PHP”. May be you can use filder name as the version name. For example for php 5.4 you can use php54.

Copy the new php folder into your xampp folder. Now go to yourxampp/apache/conf/extra folder. Open file httpd-xampp.conf from the folder extra. Change the following variables:

variable LoadFile and PHPINIDir

Variable PHPINIDir to be / Varaible LoadModule to be //php5apache2_2.dl

Save the file httpd-xampp.conf. Restart your XAMPP apache server. If your server get restarted successfully then your server php version is upgraded.

References:

http://hype-free.blogspot.in/2007/07/updating-php-in-xampp-for-windows.html

http://stackoverflow.com/questions/2154762/upgrading-php-in-xampp-for-windows

Update 2- 13-06-3013

if you see this:

C:\Program Files\php_5_4_15_Win32_VC9_x86\www\zf_project1>php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
– Installing zendframework/zendframework (2.2.0)
Downloading: 100%
Downloading: 100%
Downloading: 100%

 

[Composer\Downloader\TransportException]
The “http://nodeload.github.com/zendframework/zf2/zip/release-2.2.0&#8221; file could not be downloaded: failed to open stream: Unable to f
ind the socket transport “ssl” – did you forget to enable it when you configured PHP?

 

install [–prefer-source] [–prefer-dist] [–dry-run] [–dev] [–no-dev] [–no-custom-installers] [–no-scripts] [–no-progress] [-v|vv|vv
v|–verbose] [-o|–optimize-autoloader]

This means openssl not enabled in php, you must enable it.

So now first enable openssl php:

  1. Rename php.ini-production to php.ini (in C:\xampp\php\ folder)
  2. Edit php.ini and uncomment extension_dir=ext.
  3. Also uncomment extension=php_openssl.dll.

References:

http://stackoverflow.com/questions/1705856/socket-transport-ssl-in-php-not-enabled

http://stackoverflow.com/questions/2154762/upgrading-php-in-xampp-for-windows

Now you will be able to install ZF2.