stagem / zfc-action
ZF-Expressive 自动装配动作
0.0.1
2018-04-17 23:22 UTC
Requires
- php: >=7.0
This package is not auto-updated.
Last update: 2024-09-15 05:54:55 UTC
README
该模块允许使用一个 routes
模式为所有动作而不需要重新声明路由配置。任何动作都可以通过以下统一路径访问 /module/action。这就像标准 MVC 模式中的 /controller/action。
例如,Expressive 应用程序不关心我们为 module 关键字使用的任何 控制器。
安装
将以下内容添加到您的 composer.json
仓库声明中,并运行 composer update
// composer.json
"require": {
"stagem/zfc-action": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/stagemteam/zfc-action"
}
]
之后,在 config/config.php
中启用模块
$aggregator = new ConfigAggregator([
//...
Stagem\Server\ConfigProvider::class,
//...
], $cacheConfig['config_cache_path']);
并在 config/routes.php
中注册自动装配路由
$app->injectRoutesFromConfig((new Stagem\ZfcAction\ConfigProvider())());
注意。
slim/router
存在关于通配符路由的问题。这就是为什么您应该在composer.json
中添加以下内容的原因。
{ "require": { "acelaya/slim-2-router": "^2.7" }, "repositories": [ { "type": "vcs", "url": "https://github.com/popovserhii/slim-2-router" } ] }
使用方法
独立使用
在 src/Acme/Foo/config/module.config.php
中将模块名称与命名空间进行映射
namespace Acme\Foo;
return [
//...
'middleware' => [
'foo' => __NAMESPACE__
],
]
高级使用
高级使用允许在应用程序的所有级别使用标准化和灵活的模块命名方法。
在继续阅读之前,您应该安装
stagem/zfc-entity
自定义实现
如果您想在第三方包中使用它,您必须为使用准备 CurrentHelper。您应该在 controller/action 分发之前调用以下代码。
$this->currentHelper->setDefaultContext($actionOtControlletClassName); $this->currentHelper->setResource($request->getAttribute('controller', self::DEFAULT_RESOURCE)); $this->currentHelper->setAction($request->getAttribute('action', self::DEFAULT_ACTION)); $this->currentHelper->setRequest($request); $this->currentHelper->setRoute($route->getMatchedRoute()); $this->currentHelper->setMatchedParams($route->getMatchedParams());