1

我所有正在阅读本文的人,

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_Controller_Router_RouteZend Framework 类创建类似的 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)

注意:我对正则表达式不友好,所以我想禁止这样做,或者如果有人确切表达,将不胜感激。

4

1 回答 1

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

希望这可以帮助 :)

于 2013-03-15T08:02:33.303 回答