有人可以解释Kohana 3的路由系统吗?

ale*_*lex 9 php model-view-controller routing kohana

bootstrap.php你设置路线的地方,我很难让他们上班.我刚才读了一些文档,我似乎无法再找到解释它们的文档.这是我的一个例子

Route::set('products', 'products/(type)', array('type' => '.+'))
    ->defaults(array(
    'controller' => 'articles',
    'action' => 'view_product',
    'page' => 'shock-absorbers',
    ));
Run Code Online (Sandbox Code Playgroud)

认为这意味着products/something会加载articles控制器和action_view_product()方法的请求.但我无法让它发挥作用.

有人可以向我解释它们是如何工作的,以及所有方法参数是什么?

Luk*_*man 5

我认为这意味着像产品/某些东西的请求会加载文章控制器和 action_view_product控制器.但我无法让它发挥作用.

你的粗体部分错了.它实际上会加载文章控制器的action_view_product 方法:

class Controller_Articles extends Controller {
   public function action_view_product() {
       $params = $this->request->param(); 
       // if the uri is `products/something' then $params['type'] == 'something'
   }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

哦,天哪哦,你的上帝为什么我没注意到!

实际问题在于您的路线模式!本应该是products/(<type>),用尖括号.那些会暗示Kohana你打算将'type'作为参数名,而不是文字.