Yaf_Router::getCurrentRoute

(Yaf >=1.0.0)

Yaf_Router::getCurrentRouteRécupère le nom effectif de la route

Description

public Yaf_Router::getCurrentRoute ( void ) : string

Récupère le nom de la route actuellement en utilisation dans le processus routeur.

Note:

Vous devriez appeler cette méthode une fois le processus routeur terminé, sachant qu'avant la fin du processus, cette méthode retourne toujours NULL.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Le nom de la route effective, sous la forme d'une chaîne de caractères.

Exemples

Exemple #1 Enregistre quelques routes dans le 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);
    } 

    
/**
     * Enregistre un plugin
     */
    
public function __initPlugins(Yaf_Dispatcher $dispatcher) {
        
$dispatcher->registerPlugin(new DummyPlugin());
    }
?>

Exemple #2 plugin Dummy.php (sous le dossier 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());
    }
?>
?>

L'exemple ci-dessus va afficher quelque chose de similaire à :

/* Pour http://yourdomain.com/product/list/1
 * DummyPlugin affichera :
 */
string(7) "rewrite"

/* Pour http://yourdomain.com/product/info/34
 * DummyPlugin affichera :
 */
string(5) "regex"

/* Pour toutes les autres requêtes URI
 * DummyPlugin affichera :
 */
string(8) "_default"

Voir aussi