moln / gzfextra
1.4
2015-08-21 08:19 UTC
Requires
- php: >=5.4
- zendframework/zend-db: 2.*
- zendframework/zend-eventmanager: 2.*
- zendframework/zend-servicemanager: 2.*
Suggests
This package is not auto-updated.
Last update: 2022-02-01 12:40:19 UTC
README
Zend 框架 2 扩展
使用 Composer 安装
{
"require": {
"moln/gzfextra": "~1.0"
}
}
Db - 数据库抽象调用
ZF2 自建的 TableGateway
方法比较复杂,每个 Table 都需要在 service_manager 中添加配置。 Gzfextra\Db\TableGateway\TableGatewayAbstractServiceFactory
提供了抽象的常用 TableGateway 调用。
示例 - 使用示例
module.config.php
return array( 'service_manager' => array( 'abstract_factories' => array( 'Gzfextra\Db\TableGateway\TableGatewayAbstractServiceFactory', ), ), 'tables' => array( 'UserTable' => array( 'table' => 'users', 'invokable' => 'User\\Model\\UserTable', 'primary' => 'user_id', ), 'RoleTable' => array( 'table' => 'roles', 'invokable' => 'User\\Model\\RoleTable', 'primary' => 'role_id', ), ), );
User\Model\UserTable.php
namespace User\Model; use Zend\Db\TableGateway\TableGateway as ZendTableGateway; /** * UserTable * * 默认带有公共函数特性 * @method int fetchCount($where) * @method \ArrayObject|\Zend\Db\RowGateway\RowGateway find($id) * @method \Zend\Paginator\Paginator fetchPaginator($where = null) * @method int deletePrimary($key) */ class UserTable extends ZendTableGateway { }
控制器调用
public function indexAction() { $users = $this->getServiceLocator()->get('UserTable'); $row = $users->find(1); }
Router - 公共路由
ZF2 自带的 Zend\Mvc\ModuleRouteListener
不方便,每个新的 Controller
都需要在 ControllerPlugin
配置下。 Gzfextra\Router\GlobalModuleRouteListener
示例 - 使用示例
class Module { public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $gListener = new GlobalModuleRouteListener(); $eventManager->attach($gListener); } public function getConfig() { return GlobalModuleRouteListener::getDefaultRouterConfig(); } }
默认路由方式: /module/controller/action/param1/value1/param2/value2/...
FileStorage - 文件存储抽象
文件存储模式
- Filesystem (文件系统存储)
- Ftp (FTP 存储)
- Sftp (SFTP 存储)
示例 - 使用示例
module.config.php
工厂方式
return array( 'service_manager' => array( 'factories' => array( 'FileStorage' => '\Gzfextra\FileStorage\StorageFactory' ) ), 'file_storage' => array( 'type' => 'fileSystem', 'options' => array( 'default_path' => realpath('./public/uploads'), 'validators' => array( 'Extension' => array('gif', 'jpg', 'jpeg', 'png'), 'Size' => array('max' => 1024 * 1024), 'IsImage', ), 'filters' => array( 'LowerCaseName', 'RenameUpload' => array( 'target' => 'shop', 'use_upload_extension' => true, 'randomize' => true, ), ), ), ), );
抽象工厂
return array( 'service_manager' => array( 'abstract_factories' => array( '\Gzfextra\FileStorage\StorageAbstractFactory' ), ), 'file_storage_configs' => array( 'ImageFileStorage' => array( 'type' => 'fileSystem', 'options' => array( 'default_path' => realpath('./public/uploads'), 'validators' => array( 'Extension' => array('gif', 'jpg', 'jpeg', 'png'), 'Size' => array('max' => 1024 * 1024), 'IsImage', ), 'filters' => array( 'LowerCaseName', 'RenameUpload' => array( 'target' => 'shop', 'use_upload_extension' => true, 'randomize' => true, ), ), ), ), 'ZipFileStorage' => array( 'type' => 'ftp', 'options' => array( 'ftp' => array( 'host' => 'localhost', 'username' => 'ftpuser', 'password' => '123456', 'pasv' => true, ), 'default_path' => '/', 'validators' => array( 'Extension' => array('zip'), ), 'filters' => array( 'LowerCaseName', 'RenameUpload' => array( 'target' => 'zipfile', 'use_upload_extension' => true, 'randomize' => true, ), ), ), ), ), );
控制器调用
public function indexAction() { $fileStorage = $this->getServiceLocator()->get('ImageFileStorage'); if ($fileStorage->isValid()) { $file = $fileStorage->upload($file); // var_dump($file); } }
Tool - Gzfextra 工具
依赖 zendframework/zftool
EasyMvc - (正在评估 ZF2 框架流程是否能简化部分)
Mvc - 扩展 Mvc 模块
Gzfextra\Controller\Plugin\Params
类似 ZF1 的 $this->getParam(),默认取路由,不存在则取 POST&GET
UiFramework
目前限于 KendoUi
- KendoUi 的控制器插件