Zend框架,将URL的扩展名映射到格式参数? [英] Zend Framework, mapping the extension of a URL to the format parameter?
问题描述
可以将URL的扩展名映射到ZF中的format参数吗?
我希望默认路由仍然可以工作,包括映射参数从URI,所以你可以这样说:
http://example.com/controller/action/param1/value1/param2/value2.json
这里: $ this-> _getParam('format')=> json
这里: $ this-> _getParam ('format')=> xml
我已经调整了默认路由,但是我无法让它工作.. $ b $你可以创建一个正则表达式路由,以(\ w +)(。(\ w +))之类的东西结束。并捕捉后的部分。作为.3捕获。请参阅 Zend_Controller_Router_Route_Regex
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..
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
这篇关于Zend框架,将URL的扩展名映射到格式参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!