Zend Framework ships with a library folder and bin folder. The library folder contains all the good stuff and the bin folder contains the ZF console tool. This tool is often ignored and unused, which usually leads to statements like “what a stupid framework, I don’t like it”. The tool consists of a launcher (.bat/.sh) that initialized the zf.php file, which actually just facilitates access to the Zend_Tool package and your custom project providers and manifests. Manifests are used to import custom (non-standard) providers and providers are just classes with action methods. Each action method should be named as a verb, that indicates the action that will be taken over the project, in term of the provider name. For example “create controller” is a zf tool command that runs create() method in the controller provider. The main purpose of all this is to be able to add custom automated functionalities to your project, but could also be used for maintenance and scheduled tasks.
Setting up the ZF console tool is actually pretty easy. As long as you don’t make any preliminary mistakes.
Possible faults are:
- Make sure that there is NO .zf.ini inside your home directory (/home/username in linux and C:\Users\Username in.. you know)
- Make sure that there is no hardcoded include path that leads to the Zend folder:
php -r "echo ini_get('include_path').PHP_EOL;"
- Make sure you have a valid .zfproject.xml file in your project directory. If not, running ./zf.sh create poject in the original bin folder extracted from the archive will create a new empty project with valid .zfproject.xml file. In addition, make sure that the <projectProviderFolder/> in the xml file is enabled.
- Make sure you have a copy of Zend Framework in the library folder of your project.
- Make sure your library folder is configured as an include path in your project’s application.ini
includePaths.library = APPLICATION_PATH "/../library"
After validating the points above just copy the original bin folder from the extracted archive in your project’s root directory.
To launch the zf console tool simply type in your terminal from your project’s root directory:
If everything goes well you should see a list of all available providers and their actions. Now you can use the tool to create modules, controllers, actions, dummy dbtable models and etc. You can also write your own project providers to extend the functionalities of the zf console tool.