Yaf_Router::getCurrentRoute
(Yaf >=1.0.0)
Yaf_Router::getCurrentRoute — Get the effective route name
Описание
public string Yaf_Router::getCurrentRoute
( void
)
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"
Смотрите также
- Yaf_Bootstrap_Abstract
- Yaf_Plugin_Abstract
- Yaf_Router::addRoute() - Add new Route into Router
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Другие базовые расширения
- Yet Another Framework
- Функция Yaf_Router::addConfig() - Add config-defined routes into Router
- Функция Yaf_Router::addRoute() - Add new Route into Router
- Функция Yaf_Router::__construct() - Yaf_Router constructor
- Функция Yaf_Router::getCurrentRoute() - Get the effective route name
- Функция Yaf_Router::getRoute() - Retrieve a route by name
- Функция Yaf_Router::getRoutes() - Retrieve registered routes
- Функция Yaf_Router::route() - The route purpose
Коментарии
404 Not Found