Yaf_Router::getCurrentRoute

(Yaf >=1.0.0)

Yaf_Router::getCurrentRouteGet the effective route name

Açıklama

publicYaf_Router::getCurrentRoute(): string

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

Bilginize:

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

Bağımsız Değişkenler

Bu işlevin bağımsız değişkeni yoktur.

Dönen Değerler

String, the name of the effective route.

Örnekler

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


public function __initPlugins(Yaf_Dispatcher $dispatcher) {
$dispatcher->registerPlugin(new DummyPlugin());
}
}
?>

Örnek 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());
}
}
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

 string(7) "rewrite" string(5) "regex" string(8) "_default"

Ayrıca Bakınız

To Top