如何在Zend框架中获取发送的路由名称?

时间:2022-01-15 11:09:22

Current state:

当前状态:

  • A router is loaded from xml file
  • 路由器从xml文件加载
  • 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
  • 路由器中的两个路由名称将指向同一个控制器和操作,例如: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- languagetrainer

3 个解决方案

#1


41  

Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName()

#2


8  

Zend_Controller_Front::getInstance()->getRouter()->getCurrentRoute()

#3


3  

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 employee or trainer

会返回员工还是培训师

#1


41  

Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName()

#2


8  

Zend_Controller_Front::getInstance()->getRouter()->getCurrentRoute()

#3


3  

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 employee or trainer

会返回员工还是培训师