如何测试路由–kohana3使用手册
你可能经常想测试下你刚创建的路由。你可以直接使用 URI,但是你也可以用这里的一部分来做这个。这个部分看起来就像这样:
// 这里是你定义的路由
// ...
Route::set('post', 'post/', array('id' => '[\d]+'))
->defaults(array(
'controller' => 'post',
'action' => 'index',
));
// ...
// 测试URI
$uri = 'post/1';
// This will loop trough all the defined routes and
// tries to match them with the URI defined above
foreach (Route::all() as $r)
{
echo Kohana::debug($r->matches($uri));
}
exit;
正如你所看到的,你放置的这一小部分只是放在 bootstrap.php 文件里的路由区域的下方,并开始调试你的路由。当你运行这个的时候你会获得类似这样的信息:
array(3) (
"id" => string(1) "1"
"controller" => string(4) "post"
"action" => string(5) "index"
)
array(2) (
"controller" => string(4) "post"
"action" => string(1) "1"
)
注意:这和你所打开什么页面并无关系,只要你的 bootstrap.php 被调用(它在每个页面都有用到)