如何构造 Zend_Controller_Router_Route 来处理同一位置的操作和参数键?
这是我在 JSON 中的路线:
"jobs":
{
"type":"Zend_Controller_Router_Route",
"route":"/jobs/:action/:id/*",
"defaults":
{
"module":"api",
"controller":"jobs",
"action":"index",
"id":0
}
}
这允许像下面这样的 URI,并且到目前为止工作得很好:
/jobs/ -> action=index, id=0
/jobs/view/1 -> action=view, id=1
/jobs/edit/1 -> action=edit, id=1
但是,我希望 :action 位置也允许像这样的 URI以下内容:
/jobs/type/volunteer -> action=index, type=volunteer
/jobs/search/php%20developer -> action=index, search=php developer
到目前为止,我正在 App_Controller_Action::__call() 中完成此任务。它可以工作,但很混乱,因为在发送请求之前,操作在技术上仍然被列为“搜索”或“术语”,并且这些键的值被分配给 id。
这导致我在前端控制器插件中执行的 Zend_Acl 检查出现问题。作为解决方法,我将“搜索”和“类型”作为权限添加到我的 ACL,但同样,这很混乱。 ACL 应该保持这些语义的清晰。我希望请求在到达 ACL 插件之前被修改。
Here is my route in JSON:
"jobs":
{
"type":"Zend_Controller_Router_Route",
"route":"/jobs/:action/:id/*",
"defaults":
{
"module":"api",
"controller":"jobs",
"action":"index",
"id":0
}
}
This allows for URIs like the following and works perfectly well so far:
/jobs/ -> action=index, id=0
/jobs/view/1 -> action=view, id=1
/jobs/edit/1 -> action=edit, id=1
However, I would like the :action position to also allow for URIs like the following:
/jobs/type/volunteer -> action=index, type=volunteer
/jobs/search/php%20developer -> action=index, search=php developer
So far I'm accomplishing this within App_Controller_Action::__call(). It works, but it's messy because until the request is dispatched, the action is technically still listed as "search" or "term", and the value meant for those keys is assigned to id.
This is causing an issue in my Zend_Acl checks Im doing in a front controller plugin. As a workaround I've added "search" and "type" as permissions to my ACL but again, this is messy. The ACL should remain clean of those semantics. Id like for the request to be modified before it gets to the ACL plugin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论