Zend newbie - 基于URL的逻辑

时间:2010-08-18 19:36:36

标签: zend-framework url parameters zend-route

网址是: http://mySite.com/adminusers/listusers/

我的控制器被称为

public function listusersAction()

http://mySite.com/adminusers/listusers/regular      
http://mySite.com/adminusers/listusers/premium
http://mySite.com/adminusers/listusers/excecutive

如何在控制器文件listusersAction中捕获最后一段URL作为paremter?

感谢

1 个答案:

答案 0 :(得分:0)

我通常使用正则表达式路线来做这种事情。例如,您可以使用以下定义设置路径:

routes.adminusers-listusers.type = "Zend_Controller_Router_Route_Regex"
routes.adminusers-listusers.route = "adminusers/listusers/(\w+)"  
routes.adminusers-listusers.defaults.controller = adminusers
routes.adminusers-listusers.defaults.action = listusers
routes.adminusers-listusers.map.1 = "usertype"
routes.adminusers-listusers.reverse = "adminusers/listusers/%s"

然后,在您的控制器上,您可以通过查询请求参数来访问usertype:

$params = $this->getRequest()->getParams();
$userType = $params['usertype'];