3

如何定义一个路由来捕获所有请求并将它们转发到一个特定的控制器?我已经尝试添加默认路由

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。

4

1 回答 1

6

这应该有效:

Route::set('foobar', '<catcher>',array('catcher'=>'.*')) 
    -> defaults(array(
        'directory' => 'site',
        'controller' => 'foobar',
        'action' => 'foobar',
));

<catcher>是一个占位符并array('catcher'=>'.*')定义捕手以匹配正则表达式.*

于 2013-03-20T19:35:22.023 回答