在设置路由的 bootstrap.php
中,我很难让它们工作。我刚才读了一些文档,但我似乎再也找不到解释它们的文档了。这是我的一个例子
Route::set('products', 'products/(type)', array('type' => '.+'))
->defaults(array(
'controller' => 'articles',
'action' => 'view_product',
'page' => 'shock-absorbers',
));
我认为这意味着像products/something
这样的请求会加载articles
Controller 和action_view_product()
方法。但我无法让它工作。
谁能给我解释一下它们是如何工作的,以及所有的方法参数是什么?
最佳答案
I thought that would mean a request like products/something would load up the articles controller, and the action_view_product controller. But I can't get it to work.
你把粗体部分弄错了。它实际上会加载文章 Controller 的 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'
}
}
编辑:
天哪我怎么没注意到!!!
实际问题在于您的路由模式!应该是products/(<type>)
, 带有尖括号。这些将提示 Kohana 您打算将“类型”作为参数名称,而不是文字。
关于php - 有人可以解释一下 Kohana 3 的路由系统吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2090742/