php - 有人可以解释一下 Kohana 3 的路由系统吗?

标签 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',
    ));

认为这意味着像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/

相关文章:

javascript - Ember JS : Change path to access a route

JTabbedPane 上的 Java MVC 模式

meteor iron-router 并获取 accounts-entry 包的所有路由的名称

ruby-on-rails - 使用GPS参数处理滑轨路线

php - 本地服务器和在线服务器具有相同的时间戳但结果不同 Mysql-Php

php - 无法使用ajax将变量发送到php

php - 生成从 mysql ID 获取下一个唯一编号

php - PHP 中 SQL 的下拉列表值

swift - 自定义单元类是模型、 View 还是 Controller ?

Angular2 路由器 : matching any url, 包括子目录