2011-10-04 93 views
0

我不知道如何实现它。Zend_Router_Regex和附加参数

我有这个路由器

$route = new Zend_Controller_Router_Route_Regex(
        'category/([-\w]+)(?:/(\d+))?', 
        array('module' => 'dynamic', 'controller' => 'index', 'action' => 'show-category'), 
        array(1 => 'category', 2 => 'pageNumber'), 
        'category/%s/%d' 
    ); 

$router->addRoute('dynamic-categories', $route); 
鉴于

组装网址是/类别/新闻/ 1使用$这个 - > URL(...)帮手。我希望我的第一页新闻将成为/分类/新闻。我应该使用其他路由来做它还是使用路由器链接。我很沮丧。谢谢你的帮助。

回答

1

可以使用Zend_Controller_Router_Route直向前映射:

new Zend_Controller_Router_Route(
    '/category/:category/:page', 
    array(
     'module' => 'dynamic', 
     'controller' => 'index', 
     'action' => 'show-category', 
     'category' => 'news', 
     'page' => 1 
    ) 
) 

将匹配/category//category/news//category/othercategory/category/news/4(例子只是当然)。

+0

类别可能是新闻,文章,帖子等我应该为每个类别编写此路线规则吗? –

+0

@vredniy:我已经更新了多个类别的代码。 – Fge