Skip to content

Instantly share code, notes, and snippets.

@RenzoTejada
Last active September 4, 2016 03:53
Show Gist options
  • Save RenzoTejada/0945e14c2716dad46700 to your computer and use it in GitHub Desktop.
Save RenzoTejada/0945e14c2716dad46700 to your computer and use it in GitHub Desktop.
Un guía rápida de como usar ZFTool y la ayuda para los developers / desarrolladores / programadores en ZF2
Zend Framework 2 Tool
=========================
**ZFTool** instalar dentro de las dependencias del proyecto Zend Framework 2 .
## Configurar la instalación
* Run `composer require zendframework/zftool:dev-master`
* Habilitar el modulo ZFTool en **application.config.php**
## Features
* Class-map generator
* Listing of loaded modules
* Create a new project (install the ZF2 skeleton application)
* Create a new module
* Create a new controller
* Create a new action in a controller
* [Application diagnostics](docs/DIAGNOSTICS.md)
## Using (zftool)
1. Go to your application's directory.
2. Execute : php public/index.php
## Usage
### Basic information
php public/index.php modules [list] Muestra los modulos activos
php public/index.php version | --version Version que estamos usando de ZFTool
### Diagnostics (diagnostico de la aplicación)
php public/index.php diag [options] [module name]
[module name] (Optional) name of module to test
-v --verbose Display detailed information.
-b --break Stop testing on first failure.
-q --quiet Do not display any output unless an error occurs.
--debug Display raw debug info from tests.
### Project creation
php public/index.php create project <path>
<path> The path of the project to be created
### Module creation
php public/index.php create module <name>
Ej: php public/index.php create module Test
<name> The name of the module to be created
### Controller creation:
php public/index.php create controller <name> <module>
Ej: php public/index.php create controller Index Test
<name> The name of the controller to be created
<module> The module in which the controller should be created
### Action creation:
php public/index.php create action <name> <controller> <module>
Ej: php public/index.php create action Index Index Test
<name> The name of the action to be created
<controller> The name of the controller in which the action should be created
<module> The module containing the controller
### Application configuration
php public/index.php config list list all configuration option
php public/index.php config get <name> display a single config value, i.e. "config get db.host"
php public/index.php config set <name> <value> set a single config value (use only to change scalar values)
### Classmap generator
php public/index.php classmap generate <directory> <classmap file> [--append|-a] [--overwrite|-w]
Ej: php public/index.php classmap generate module/Test -a
php public/index.php classmap generate module/Test -w
<directory> The directory to scan for PHP classes (use "." to use current directory)
<classmap file> File name for generated class map file or - for standard output. If not supplied, defaults to
autoload_classmap.php inside <directory>.
--append | -a Append to classmap file if it exists / Solo agrega sin importar si ya anteriormente estaba (duplicidad)
--overwrite | -w Whether or not to overwrite existing classmap file / Recorre todo y crea un nuevo archivo sin data duplicada (mejor opción)
### Recomendación para poder crear correctamente un module, controller y action en ZF2
1. Crear un modulo nuevo
Ej: php public/index.php create module Test
Acciones: Se creara el modulo Test y se creara un archivo nuevo de config/application.config.php
2. Crear un controlador nuevo
Ej: php public/index.php create controller Index Test
Acciones: se creara el archivo IndexController.php con al Action Index
NOTA: al ingresar al ruta del nuevo controlador nos saldra un error 404
Ruta: test/index/index
Solución: Ejecutar lo siguiente
a. php public/index.php classmap generate module/Test -w
b. Verificar que tenga el router para el modulo Test (module.config.php)
Ej:
'router' => array(
'routes' => array(
'test' => array(
'type' => 'Literal',
'options' => array(
'route' => '/test',
'defaults' => array(
'__NAMESPACE__' => 'Test\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
c. agregar el controller en la variable **controllers**
'controllers' => array(
'invokables' => array(
'Test\Controller\Index' => 'Test\Controller\IndexController',
),
),
d. agregar view manager
'view_manager' => array(
'template_path_stack' => array(
'Test' => __DIR__ . '/../view',
),
),
e. Todo estas keys deben estan dentro del array
f. estos pasos anteriores se hacen siempre en la primera vez en la segunda vez solo se realizará los pasos -> a y c.
3.- Crear un action test.
Ej: php public/index.php create action Test Index Test
Acciones: se agregará la action en el controller, y se creara el archivo .phtml dentro del directorio view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment