【发布时间】:2013-03-20 19:03:55
【问题描述】:
如何定义一个路由来捕获所有请求并将它们转发到一个特定的控制器?我已经尝试添加默认路由
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'directory' => 'site',
'controller' => 'foobar',
'action' => 'foobar',
));
或
Route::set('default', '(.*)')
-> defaults(array(
'directory' => 'site',
'controller' => 'foobar',
'action' => 'foobar',
));
到我的 bootstrap.php,但它不起作用。输入 localhost/a 后,我得到了
Unable to find a route to match the URI: a
或
The requested URL a was not found on this server.
错误。我确定控制器是有效的,因为
Route::set('foobar', 'foo')
-> defaults(array(
'directory' => 'site',
'controller' => 'foobar',
'action' => 'foobar',
));
工作正常。
我使用的是 Kohana 3.3。
【问题讨论】:
-
你为什么要这样做?这将超出 kohana 的 MVC 的目的
-
我正在尝试创建站点构建服务,并且我想将所有非管理员站点存储在数据库中并在需要时加载它们。这些站点将被动态添加(我无法对路线进行硬编码);我不希望它们只能通过 localhost/index.php?id=7 使用,而是通过 localhost/siteName 提供。控制器基本上会为每个站点做同样的事情——加载标题、元标记、内容等。然而,管理站点通常是路由的,但我需要一些东西来访问普通文档。
-
希望我的回答有帮助