Yaf_Router::getCurrentRoute

(Yaf >=1.0.0)

Yaf_Router::getCurrentRouteGet the effective route name

Description

public Yaf_Router::getCurrentRoute(): string

Get the name of the route which is effective in the route process.

Note:

You should call this method after the route process finished, since before that, this method will always return null.

Parameters

This function has no parameters.

Return Values

String, the name of the effective route.

Examples

Example #1 Register some routes in 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());
    }
}
?>

The above example will output something similar to:

/* 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"

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial