为分页,排序和过滤器创建URL - ZF

时间:2013-03-14 22:43:31

标签: php zend-framework url url-rewriting zend-router

我是每个正在读这篇文章的人,

我5分钟前在网上找到了一个非常好的网址:

www.exemple.com/blog/rating.asc/2

与:

有关
blog => controller/action/module or anything
rating => ordered by
asc => order of list
2 => current page

我想知道如何使用Zend Framework的Zend_Controller_Router_Route类创建类似的URL。

对于我的网站,它会像:

www.exemple.com/portfolio/date.asc/2

www.exemple.com/blog/author.desc/ (page optional, default 1)

www.exemple.com/blog/ (default order: date.asc, page: 1)

注意:我对Regex并不友好,所以我想禁止那个,或者如果有人表达了确切的话,我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

嘿,我不确定你是否使用ini进行配置,但如果我有以下内容,我就会这样做:

module     => blog
controller => article
action     => list
// Parameter to get from the request in the controller
// Note that those are the defaults in case you don't provide any parameters in the url
sortBy => author
order  => asc
page   => 1   
ini文件中的

; /www.exemple.com/blog/articles/author/desc/2
resources.router.routes.whateverroutname.route = /blog/articles/:sortBy/:order/:page
resources.router.routes.whateverroutname.defaults.module = blog
resources.router.routes.whateverroutname.defaults.controller = article
resources.router.routes.whateverroutname.defaults.action = list
resources.router.routes.whateverroutname.defaults.sortBy = author
resources.router.routes.whateverroutname.defaults.order = asc
resources.router.routes.whateverroutname.defaults.page = 1

希望这会有所帮助:)