xml 如何在 Zend 框架中获取调度的路由名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1373573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the dispatched route name in Zend framework?
提问by Murat ?orlu
Current state:
当前状态:
- A router is loaded from xml file
- two route name within the router are going to the same controller and action, for example: www-language-employee and www-language-trainer are going to the same controller and action --> EmployeeController & listemployeeAction
- 从 xml 文件加载路由器
- 路由器内的两个路由名称将前往相同的控制器和动作,例如:www-language-employee 和 www-language-trainer 将前往相同的控制器和动作 --> EmployeeController & listemployeeAction
Problem: - Need to know which route name is dispatched/being used from a request.
问题: - 需要知道从请求中分派/正在使用哪个路由名称。
Example: 1. http://www.mycompany.com/en/trainers/Expected return value: www-language-trainer
示例: 1. http://www.mycompany.com/en/trainers/预期返回值:www-language-trainer
回答by Murat ?orlu
Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName()
回答by Tomá? Fejfar
Zend_Controller_Front::getInstance()->getRouter()->getCurrentRoute()
回答by Sparkup
In my case :
就我而言:
Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName()
returns Employeecontroller/:listemployee
返回 Employeecontroller/:listemployee
In Employeecontroller:
在Employeecontroller:
public function listemployeeAction()
{
$this->getRequest()->getParam('listemployee')
}
would return either employeeor trainer
将返回employee或trainer

