Zend Router 各种 URL

发布于 2024-09-01 09:04:22 字数 543 浏览 9 评论 0 原文

我想用 ZF 路由器实现类似的目标。 ('controller' => 'products', 'action' => 'index')

//Show product details   
'http://mydomain.com/en/products/category-1/subcategory-3/product-name.htm'

//List products in subcategory-3
'http://mydomain.com/en/products/category-1/subcategory-3.htm'

//List products in category-1
'http://mydomain.com/en/products/category-1.htm'

//List products in all categories
'http://mydomain.com/en/products.htm'

我是否必须将每种可能性指定为单独的路线?或者有更好的解决方案吗? (使用Route_Regex?)

I would like to achieve something like this with ZF router. ('controller' => 'products', 'action' => 'index')

//Show product details   
'http://mydomain.com/en/products/category-1/subcategory-3/product-name.htm'

//List products in subcategory-3
'http://mydomain.com/en/products/category-1/subcategory-3.htm'

//List products in category-1
'http://mydomain.com/en/products/category-1.htm'

//List products in all categories
'http://mydomain.com/en/products.htm'

Do I have to specify each possibility as separate route? Or is there better solution? (Using Route_Regex?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2024-09-08 09:04:22

您可以通过使用空默认值来获得近似的路由,如下所示:

resources.router.routes.products.route = ":lang/products/:category/:subcategory/:product"
resources.router.routes.products.defaults.category=""  
resources.router.routes.products.defaults.subcategory=""       
resources.router.routes.products.defaults.product=""
resources.router.routes.products.defaults.controller="products"
resources.router.routes.products.defaults.action="index"

该路由不会处理 /en/products.htm 上的 .htm 扩展名,并且类别/子类别/产品的值可能会附加一个 .htm。使用一点 .htaccess RewriteRule 魔法从请求中剥离 .htm 可能比使用基本的 Zend_Router 更容易处理)

 RewriteRule /([^/]+)/products(.*)\.htm /$1/products$2

另一种方法是使用自定义或正则表达式路由

You can get a route to approximate that by having empty defaults like so:

resources.router.routes.products.route = ":lang/products/:category/:subcategory/:product"
resources.router.routes.products.defaults.category=""  
resources.router.routes.products.defaults.subcategory=""       
resources.router.routes.products.defaults.product=""
resources.router.routes.products.defaults.controller="products"
resources.router.routes.products.defaults.action="index"

That route isn't going to handle your .htm extension on /en/products.htm, and the category/subcategory/product might have a .htm appended to their values. It is probably easier to handle stripping the .htm from the request with a little .htaccess RewriteRule magic rather than working around it with basic Zend_Router)

 RewriteRule /([^/]+)/products(.*)\.htm /$1/products$2

The alternative would be to use a Custom or Regular Expression route

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文