2011-09-21 94 views
0

我有一个文章模型和一个类别模型,都带有一个url_slug变量(我想在URL中显示时寻找它)。这里是我如何拥有网址出现:与Kohana 3的定制嵌套路由

//list all of the articles 
http://example.com/articles 

//list of all the articles in that category 
http://example.com/articles/:category_slug 

//a single article. 
http://example.com/articles/:category_slug/:article_slug 

我应该怎么设置文章控制器和/或为了实现这一目标的途径

回答

0

您可以使用这样

Route::set('articles', '/articles(/<category_filter>(/<article_id>))', array(
    'controller' => 'Articles', 
    'action' => '(index)' 
)) 
->defaults(array(
    'controller' => 'Articles', 
    'action'  => 'index', 
)); 

路线在你的控制?您可以使用

$category = Request::current()->param('category_filter'); 
$article_id = Request::current()->param('article_id'); 

并相应地过滤您的输出。