【问题标题】:custom nested routes with Kohana 3Kohana 3 自定义嵌套路由
【发布时间】:2011-09-21 19:55:58
【问题描述】:

我有一个 Articles 模型和一个 Category 模型,都带有一个 url_slug 变量(我希望在查找它时显示在 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

我应该如何设置文章控制器和/或路由以实现此目的?

【问题讨论】:

    标签: routes kohana


    【解决方案1】:

    你可以使用这样的路线

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

    在您的控制器中,您可以使用

    访问过滤器/ID
    $category   = Request::current()->param('category_filter');
    $article_id = Request::current()->param('article_id');
    

    并相应地过滤您的输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多