Routes 使用Kohana 3的自定义嵌套管线
我有一个文章模型和一个类别模型,两者都带有Routes 使用Kohana 3的自定义嵌套管线,routes,kohana,Routes,Kohana,我有一个文章模型和一个类别模型,两者都带有url\u slug变量(我希望在查找url时在url中显示的内容。下面是我希望url显示的方式: //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://exam
url\u slug
变量(我希望在查找url时在url中显示的内容。下面是我希望url显示的方式:
//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
我应该如何设置文章控制器和/或路由以实现这一点?您可以使用这样的路由
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');