Zend Framework 路由子文件夹与 Rest
对于我当前的应用程序设置,我正在尝试为标准控制器和休息控制器创建路由。
这是我的结构。
/application
/modules
/module
/controllers
/Admin
/Api
要调用 admin 子文件夹中的控制器:
/module/admin_controller/action
我想将其更改为:
/admin/module/controller/action
在我当前的设置中:
/* application.ini */
;Default route
resources.router.routes.defaultmodule.type = Zend_Controller_Router_Route_Module
resources.router.routes.defaultmodule.defaults.module = "default
; APi route
resources.router.routes.api.type = Zend_Controller_Router_Route
resources.router.routes.api.route = ":api"
resources.router.routes.api.reqs.api = "api"
resources.router.routes.apichain.type = Zend_Controller_Router_Route_Chain
resources.router.routes.apichain.chain = "api, defaultmodule"
; Admin route
resources.router.routes.admin.type = Zend_Controller_Router_Route
resources.router.routes.admin.route = ":admin"
resources.router.routes.admin.reqs.admin = "admin"
resources.router.routes.adminchain.type = Zend_Controller_Router_Route_Chain
resources.router.routes.adminchain.chain = "admin, defaultmodule"
/* Plugin */
class Pwb_Plugin_ControllerRoute
extends Zend_Controller_Plugin_Abstract
{
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
if ($request->getParam('admin')) {
$admin_controller = $request->getParam('admin') . '_' . $request->getControllerName();
$request->setControllerName($admin_controller);
}
if ($request->getParam('api')) {
$admin_controller = $request->getParam('api') . '_' . $request->getControllerName();
$request->setControllerName($admin_controller);
}
}
}
/* Module Bootstrap */
class Acl_Bootstrap
extends Zend_Application_Module_Bootstrap
{
protected function _initRestRoute()
{
$this->bootstrap('frontController');
$frontController = Zend_Controller_Front::getInstance();
$restRoute = new Zend_Rest_Route(
$frontController,
array(),
array(
'acl' => array(
'api_role'
))
);
$frontController->getRouter()->addRoute('restAcl', $restRoute);
}
}
这里的问题实际上是 API 文件夹中的某些控制器是 Rest,但不是全部。
/api/acl/role 按预期正确路由到 indexAction。
/api/acl/role/1 正在寻找操作“1”,我希望它路由到 getAction。
我如何将 Bootstrap 模块中的 Zend_Route_Rest 集成到这些规则集中。
每一个帮助将不胜感激。
For my current Application Setup i am trying to create a routing for Standard Controllers and Rest Controllers.
This is my Structure.
/application
/modules
/module
/controllers
/Admin
/Api
To call a Controller within the admin Sub Folder:
/module/admin_controller/action
I want to change this to:
/admin/module/controller/action
In my current setup:
/* application.ini */
;Default route
resources.router.routes.defaultmodule.type = Zend_Controller_Router_Route_Module
resources.router.routes.defaultmodule.defaults.module = "default
; APi route
resources.router.routes.api.type = Zend_Controller_Router_Route
resources.router.routes.api.route = ":api"
resources.router.routes.api.reqs.api = "api"
resources.router.routes.apichain.type = Zend_Controller_Router_Route_Chain
resources.router.routes.apichain.chain = "api, defaultmodule"
; Admin route
resources.router.routes.admin.type = Zend_Controller_Router_Route
resources.router.routes.admin.route = ":admin"
resources.router.routes.admin.reqs.admin = "admin"
resources.router.routes.adminchain.type = Zend_Controller_Router_Route_Chain
resources.router.routes.adminchain.chain = "admin, defaultmodule"
/* Plugin */
class Pwb_Plugin_ControllerRoute
extends Zend_Controller_Plugin_Abstract
{
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
if ($request->getParam('admin')) {
$admin_controller = $request->getParam('admin') . '_' . $request->getControllerName();
$request->setControllerName($admin_controller);
}
if ($request->getParam('api')) {
$admin_controller = $request->getParam('api') . '_' . $request->getControllerName();
$request->setControllerName($admin_controller);
}
}
}
/* Module Bootstrap */
class Acl_Bootstrap
extends Zend_Application_Module_Bootstrap
{
protected function _initRestRoute()
{
$this->bootstrap('frontController');
$frontController = Zend_Controller_Front::getInstance();
$restRoute = new Zend_Rest_Route(
$frontController,
array(),
array(
'acl' => array(
'api_role'
))
);
$frontController->getRouter()->addRoute('restAcl', $restRoute);
}
}
The issue here really is that some Controllers in the API folder are Rest but not all of them.
/api/acl/role is routing correctly to the indexAction as expected.
/api/acl/role/1 is looking for the action "1" where i would expect it to route to getAction.
How could i integrate the Zend_Route_Rest from the module Bootstrap into these rulesets.
Every help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对多个类进行了子类化以实现此目的,并为 admin/api 创建了静态路由
I have Subclassed multiple classes to achieve this and created static routes for admin/api