Zend Framework, mapping the extension of a URL to the format parameter?

与世无争的帅哥 提交于 2019-12-23 12:23:42

问题


It is possible to map the extension of a URL, to the format parameter in ZF?

I'd like the default routing to still work, including mapping parameters from the URI, so you'd be able to say:

http://example.com/controller/action/param1/value1/param2/value2.json

Here: $this->_getParam('format') => "json"

And likewise:

http://example.com/module/controller/action/param1/value1/param2/value2.xml

Here: $this->_getParam('format') => "xml"

I've fiddled with the default routes, but i cannot get it to work..


回答1:


You could create a regex route, ending with something like (\w+)(.(\w+))? and capture the part after the . as the .3 capture. see Zend_Controller_Router_Route_Regex



来源:https://stackoverflow.com/questions/1202414/zend-framework-mapping-the-extension-of-a-url-to-the-format-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!