t4web / crud
ZF2 Module. Abstract layer for manage domain entity
Installs: 1 497
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 1
Requires
- php: >=5.5
- sebaks/controller: ~0.1.0
- t4web/domain: ~1.2.0
- zendframework/zend-eventmanager: >=2.6
- zendframework/zend-http: >=2.6
- zendframework/zend-modulemanager: >=2.6
- zendframework/zend-mvc: >=2.6
- zendframework/zend-view: >=2.6
Requires (Dev)
- phpunit/phpunit: ~4.5
- squizlabs/php_codesniffer: ^2.3
README
ZF2 Module. Abstract layer for manage domain entity
Contents
Installation
Add this project in your composer.json:
"require": { "t4web/crud": "~1.0.0" }
Now tell composer to download T4web\Crud
by running the command:
$ php composer.phar update
Post installation
Enabling it in your application.config.php
file.
<?php return array( 'modules' => array( // ... 'T4web\Crud', ), // ... );
Introduction
This module generate CRUD routes and provides basic CRUD methods and customization it. In our vision CRUD contain 6 actions:
new
- action, which display form for new entry,create
- action, which receive array of entry values, it validate values and create entity,read
- action, which display one entity, it validate criteria param and entry exists,update
- action, which receive array of entry values, it validate criteria param and entry exists and validate values + update entity,delete
- action, which delete one entity, it validate criteria param and entry exists,list
- action, which display entities by criteria (filter)
Also this module provide Abstract factories for creating Domain services by short alias:
ENTITY_NAME-crud-create-service
-T4webDomain\Service\Creator
will be createdENTITY_NAME-crud-read-service
-T4web\Crud\Service\ReadService
will be createdENTITY_NAME-crud-update-service
-T4webDomain\Service\Updater
will be createdENTITY_NAME-crud-delete-service
-T4webDomain\Service\Deleter
will be createdENTITY_NAME-crud-list-service
-T4web\Crud\Service\ListService
will be created
Configuration options
For use T4web\Crud
featuers you must define route-generation
config:
'route-generation' => [ [ 'entity' => 'user', 'backend' => [ 'namespace' => '/backend', 'actions' => [ 'new', 'create', 'read', 'update', 'delete', 'list', ], 'options' => [ 'create' => [ 'changesValidator' => Action\Admin\User\CreateAction\ChangesValidator::class, 'controller' => Action\Admin\User\CreateAction\Controller::class, 'allowedMethods' => ['POST'], 'service' => 'user-crud-delete-service', 'redirectTo' => 'admin-user-list', ], 'update' => [ 'changesValidator' => Action\Admin\User\CreateAction\ChangesValidator::class, ], ], ], ], ],
where entity
- entity name for URI (for example: /backend/user/new
, '/backend/user/create'...),
actions
- define which actions will be processed, if you not define delete
action, delete URI will not created,
options
- define custom options for each action (see sebaks/zend-mvc-controller)
For current config will be created this routes:
'routes' => [ 'admin-user-new' => [ 'type' => 'Segment', 'options' => [ 'route' => '/backend/user/new', 'defaults' => [ 'allowedMethods' => ['GET'], 'controller' => 'sebaks-zend-mvc-controller', ], ], ], 'admin-user-create' => [ 'type' => 'Segment', 'options' => [ 'route' => '/backend/user/create', 'defaults' => [ 'allowedMethods' => ['POST'], 'controller' => 'Users\Action\Admin\User\CreateAction\Controller', 'service' => 'user-crud-create-service', 'redirectTo' => 'admin-user-list', 'changesValidator' => 'Users\Action\Admin\User\CreateAction\ChangesValidator', ], ], ], 'admin-user-read' => [ 'type' => 'Segment', 'options' => [ 'route' => '/backend/user/read/:id', 'defaults' => [ 'allowedMethods' => ['GET'], 'controller' => 'sebaks-zend-mvc-controller', 'routeCriteria' => 'id', 'service' => 'user-crud-read-service', 'criteriaValidator' => 'user-crud-id-validator', ], ], ], 'admin-user-update' => [ 'type' => 'Segment', 'options' => [ 'route' => '/backend/user/update/:id', 'defaults' => [ 'allowedMethods' => ['POST'], 'controller' => 'sebaks-zend-mvc-controller', 'routeCriteria' => 'id', 'criteriaValidator' => 'user-crud-id-validator' 'service' => 'user-crud-update-service', 'redirectTo' => 'admin-user-list', ], ], ], 'admin-user-delete' => [ 'type' => 'Segment', 'options' => [ 'route' => '/backend/user/delete/:id', 'defaults' => [ 'allowedMethods' => ['GET'], 'controller' => 'sebaks-zend-mvc-controller', 'routeCriteria' => 'id', 'criteriaValidator' => 'user-crud-id-validator' 'service' => 'user-crud-delete-service', 'redirectTo' => 'admin-user-list', ], ], ], ]