(Yaf >=1.0.0)
Yaf_Router::getCurrentRoute — 获取生效的路由名称
此函数没有参数。
字符串,生效路由的名称。
示例 #1 在 Bootstrap 中注册一些路由
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
public function _initConfig() {
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
}
public function _initRoute(Yaf_Dispatcher $dispatcher) {
$router = $dispatcher->getRouter();
$rewrite_route = new Yaf_Route_Rewrite(
"/product/list/:page",
array(
"controller" => "product",
"action" => "list",
)
);
$regex_route = new Yaf_Route_Rewrite(
"#^/product/info/(\d+)",
array(
"controller" => "product",
"action" => "info",
)
);
$router->addRoute('rewrite', $rewrite_route)->addRoute('regex', $regex_route);
}
/**
* 注册插件
*/
public function __initPlugins(Yaf_Dispatcher $dispatcher) {
$dispatcher->registerPlugin(new DummyPlugin());
}
}
?>
示例 #2 插件 Dummy.php (在 application.directory/plugins 下)
<?php
class DummyPlugin extends Yaf_Plugin_Abstract {
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump(Yaf_Dispatcher::getInstance()->getRouter()->getCurrentRoute());
}
}
?>
上面的例子将输出类似以下内容
/* for http://yourdomain.com/product/list/1 * DummyPlugin will output: */ string(7) "rewrite" /* for http://yourdomain.com/product/info/34 * DummyPlugin will output: */ string(5) "regex" /* for other request URI * DummyPlugin will output: */ string(8) "_default"