array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'yaf-router.getcurrentroute.php', 1 => 'Yaf_Router::getCurrentRoute', 2 => 'Get the effective route name', ), 'up' => array ( 0 => 'class.yaf-router.php', 1 => 'Yaf_Router', ), 'prev' => array ( 0 => 'yaf-router.construct.php', 1 => 'Yaf_Router::__construct', ), 'next' => array ( 0 => 'yaf-router.getroute.php', 1 => 'Yaf_Router::getRoute', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/yaf/yaf_router/getcurrentroute.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

Yaf_Router::getCurrentRoute

(Yaf >=1.0.0)

Yaf_Router::getCurrentRouteGet the effective route name

Опис

public Yaf_Router::getCurrentRoute(): string

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

Зауваження:

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

Параметри

У цієї функції немає параметрів.

Значення, що повертаються

String, the name of the effective route.

Приклади

Приклад #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());
}
}
?>

Приклад #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());
}
}
?>

Поданий вище приклад виведе щось схоже на:

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

Прогляньте також