Yaf_Router::getCurrentRoute

(Yaf >=1.0.0)

Yaf_Router::getCurrentRoute取锟矫碉拷前锟斤拷效锟斤拷路锟斤拷锟斤拷

说锟斤拷

public Yaf_Router::getCurrentRoute ( void ) : string

锟斤拷取锟斤拷前路锟缴斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫碉拷路锟斤拷锟斤拷

Note:

锟斤拷锟斤拷要锟斤拷路锟缴斤拷锟教斤拷锟斤拷之锟斤拷锟斤拷么朔锟斤拷锟斤拷锟斤拷锟斤拷锟街帮拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一直锟斤拷锟斤拷NULL

Warning

锟斤拷锟斤拷锟斤拷锟斤拷未锟斤拷写锟侥碉拷锟斤拷锟斤拷锟叫诧拷锟斤拷锟叫憋拷

锟斤拷锟斤拷

锟剿猴拷锟斤拷没锟叫诧拷锟斤拷锟斤拷

锟斤拷锟斤拷值

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);
    } 

    
/**
     * register plugin 
     */
    
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 $requestYaf_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"

锟轿硷拷