Search code examples
zend-framework2zftool2

ZFTool 2 – How to create an action?


I am using the ZFTool 2 to create modules and controllers in my projects. When I try to use it to create an action, I encounter an error.

In the documentation it says the following:

Action creation:
  zftool create action <name> <controllerName> <module> [<path>]    create an action in a controller                                                          

  <name>              The name of the action to be created                                                                                                                          
  <controllerName>    The name of the controller in which the action should be created                                                                                              
  <module>            The module containing the controller                                                                                                                          
  <path>              The root path of a ZF2 application where to create the action          

So I entered the following into Terminal:

zftool create action test Index Mymodule my-project-root

I get the following (not that helpful) error message back:

Reason for failure: Invalid arguments or no arguments provided

I also tried it like this, with the same result:

zftool create action testAction IndexController Mymodule my-project-root

Am I doing something wrong here? Why is my action not created? What arguments are invalid?

EDIT
As suggested in the comments I also tried to create the action after changing into the project root to make sure the path is not the problem. I got the following error message:

Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZFTool) could not be initialized.' in /Applications/AMPPS/www/myProject/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:189


Solution

  • Probably the last argument my-project-root is wrong. It should represent a correct physical root path of a ZF2 application.

    Try this:

    zftool create action foobar   Index        Application /path/to/your/project
                         [action] [Controller] [Module]    [Your project root]
    

    EDIT: After your updates, i realized that problem may related with your ZFTool installation. (Assuming that you're trying to use zftool as an external command). Try to attach it as module into your project:

    $ cd /path/to/your/projectroot
    $ php composer.phar selfupdate
    $ php composer.phar require --dev zendframework/zftool:dev-master
    $ ./vendor/bin/zf.php create action foobar Index Application
    

    As you can see, there are no need to setting project root explicitly in this approach.