Welcome to Abdul Malik Ikhsan's Blog

Zend Framework 2 : ZFTool – Zend Framework 2 Module to Ease Development

Posted in Tutorial PHP, Zend Framework 2 by samsonasik on January 16, 2013

zf2-zendframework2ZFTool is an utility module for maintaining modular Zend Framework 2 applications. It runs from the command line and can be installed as ZF2 module or as PHAR.
It currently can show installed modules, create a new module, or create a project.
1. Installation
Open your composer.json in your skeleton application :

{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.*",
        "zendframework/zftool": "dev-master"
    }
}

and add “zendframework/zftool”: “dev-master” in require, and run :

php composer.phar self-update && php composer.phar update 

OR, you can remove above step by run the following :

composer require zendframework/zftool:dev-master

and You will see process like this :
zftool_img1
and your downloaded ZFTool show in your vendor folder.
Last step for installation, edit your config/application.config.php and add ZFTool to modules array.

2. Using ZFTool
a. Getting started : Show list commands
Type :

php public/index.php

and you will see the following list :
zftool_img2

b. show modules
Type :

php public/index.php modules

and you will see like the following :
zftool_img3

c. create module
Type :

//testmodule is name of module we want to create
php public/index.php create module testmodule

and if success, you will see like the following :
zftool_img4

d. create a project
Type :

//new_prj is name of project we want to create
php public/index.php create project ../new_prj

and if success, you will see like the following :
zftool_img5

References :
https://github.com/zendframework/ZFTool

Advertisements

19 Responses

Subscribe to comments with RSS.

  1. JuanRoman said, on January 18, 2013 at 1:04 am

    I’m getting the follwing error when composer update:

    – zendframework/zftool dev-master requires zendframework/zend-version >=2.0.0 -> no matching package found.

    This is my composer.json:

    “name”: “zendframework/skeleton-application”,
    “description”: “Skeleton Application for ZF2”,
    “license”: “BSD-3-Clause”,
    “keywords”: [
    “framework”,
    “zf2”
    ],
    “homepage”: “http://framework.zend.com/”,
    “minimum-stability”: “alpha”,
    “require”: {
    “php”: “>=5.3.3”,
    “zendframework/zendframework”: “2.*”,
    “zendframework/zend-config”: “2.0.*”,
    “zendframework/zend-http”: “2.0.*”,
    “phpunit/phpunit”: “3.7.*”,
    “doctrine/common” : “>=2.1”,
    “doctrine/migrations” : “dev-master”,
    “doctrine/doctrine-orm-module”: “0.*”,
    “zendframework/zend-developer-tools”: “dev-master”,
    “bjyoungblood/BjyProfiler”: “dev-master”,
    “zendframework/zftool”: “dev-master”
    }

    Thanks in advance, great blog!

    • samsonasik said, on January 18, 2013 at 1:26 am

      try to change minimum-stability to dev.

      You’re welcome ๐Ÿ˜‰

      • JuanRoman said, on January 18, 2013 at 1:58 am

        That did it! thx again!

      • samsonasik said, on January 18, 2013 at 2:31 am

        You’re welcome ๐Ÿ˜‰

  2. JuanRoman said, on January 23, 2013 at 2:13 am

    I’m having problems creating a module, i get the following error:

    PHP Parse error: syntax error, unexpected ‘[‘ in /var/www/zf2_new_app/vendor/zendframework/zftool/src/ZFTool/Controller/CreateController.php on line 53

    I’m running “php public/index.php create module mymodule” in my root zf2 application folder,

    Thanks again!

    • samsonasik said, on January 23, 2013 at 2:27 am

      what line 53 code ? i’m using mac and it’s just work

  3. JuanRoman said, on January 23, 2013 at 2:32 am

    here’s the line:

    $tmpSkeleton = $tmpDir . ‘/’ . rtrim($zip->statIndex(0)[‘name’], “/”);

    I’m in a linux dev server

    • samsonasik said, on January 23, 2013 at 2:39 am

      my temporary answer, clone my old fork : https://github.com/samsonasik/ZFTool ,

      the line 53 is not same as yours. I think it’s your php version problem in $zip->statIndex(0)[‘name’] that should be only for php 5.4 ๐Ÿ™‚

      • JuanRoman said, on January 23, 2013 at 3:18 am

        I’m seeing the same line 53 of /src/ZFTool/Controller/CreateController.php on your git

        unless i’m missing something…

      • samsonasik said, on January 23, 2013 at 3:36 am

        Oops, You’re right, change line 53 with this :

                    $stateIndex0 = $zip->statIndex(0);
                    $tmpSkeleton = $tmpDir . '/' . rtrim($stateIndex0['name'], "/");
        

        I just sent a PR here : https://github.com/zendframework/ZFTool/pull/13 , Thank You ๐Ÿ˜‰

  4. JuanRoman said, on January 23, 2013 at 3:42 am

    That did it, thx again man!

  5. Igor said, on January 26, 2013 at 10:45 pm

    Put minimun-stability like dev is not fix to problem, is a workaroud, here he removes the zendframework 2.0.6 and clone the zendframework in dev…this a risk for development to put in production.

    oh, I written an email for you, and you dont response me, all right, i know that youtput your email for anyone write an email for you.

    thanks

    • samsonasik said, on January 27, 2013 at 12:15 am

      I don’t recommend to write minimum-stability, but if it needed, it should be dev and you should just update, not re-install. You can go to https://github.com/zendframework/ZFTool and click ZIP download button anyway.

      I didn’t find email from you, maybe re-send again ? ๐Ÿ™‚

  6. Leo said, on January 30, 2013 at 9:30 am

    When I use php public/index.php create project new_prj on the console, It returns ” I can’t use the API of github”. Do you know what this is?

  7. engineersexperience said, on September 5, 2013 at 7:14 pm

    very useful for beginers

  8. andreea115 said, on February 1, 2014 at 5:02 am

    Hello Samsonasik
    thank you so much for this tutorial; i was really stock on this issue; you really just saved me. thanks


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: