2009年1月3日星期六

[fw-mvc] Question about reversed routes

Hi everybody,

I have the following issue, I have a routes.ini with this to browse some brand products and generate urls like this:
site.com/brands/nike
site.com/brands/nike/2 for page two
so the .ini file looks like this:

# Browse brands:
browse_brands.defaults.controller = browse
browse_brands.defaults.action = "brand"
browse_brands.type = "Zend_Controller_Router_Route_Regex"
browse_brands.route = "brands/([^/]+)(?:/(.+))?"
browse_brands.reqs.brand = "(.+)"
browse_brands.map.1 = "brand"
browse_brands.map.2 = "page"
browse_brands.reverse = "brands/%s"

The problem it's with the reverse option I need to specify to use the view url helper. As long as the page number it's an optional parameter, I have no idea on how to configure it:

This obviously works:
<a href="<?php echo $this->url( array( 'controller' => 'browse', 'action' => 'brand', 'brand' => 'nike' ), 'browse_brands' ) ?>">Nike</a>

But this don't:
<a href="<?php echo $this->url( array( 'controller' => 'browse', 'action' => 'brand', 'brand' => 'nike', 'page' => 2 ), 'browse_brands' ) ?>">Nike page 2</a>

I've searched in the documentation and I haven't found anything about optional parameters in the route regex.

Thanks in advance.





Jose

没有评论: