©
This document uses PHP Chinese website manual Release
(Yaf >=1.0.0)
Yaf_Router::getCurrentRoute — 取得当前有效的路由名
获取当前路由进程中正在起作用的路由名
Note:
你需要在路由进程结束之后调用此方法,在这之前,这个方法会一直返回NULL
本函数还未编写文档,仅有参数列表。
此函数没有参数。
String,当前起效的路由的名字
Example #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 ());
}
?>
Example #2 plugin Dummy.php (under 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 ());
}
?>
?>
以上例程的输出类似于:
string(7) "rewrite" string(5) "regex" string(8) "_default"