Yaf_Router::addRoute
(Yaf >=1.0.0)
Yaf_Router::addRoute — Add new Route into Router
Description
public bool Yaf_Router::addRoute
( string
$name
, Yaf_Route_Abstract $route
)defaultly, Yaf_Router using a Yaf_Route_Static as its defualt route. you can add new routes into router's route stack by calling this method.
the newer route will be called before the older(route stack), and if the newer router return
TRUE
, the router process will be end. otherwise, the older one will be
called.
Parameters
This function has no parameters.
Return Values
Examples
Example #1 Yaf_Dispatcher::autoRender()example
<?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();
/**
* we can add some pre-defined routes in application.ini
*/
$router->addConfig(Yaf_Registry::get("config")->routes);
/**
* add a Rewrite route, then for a request uri:
* http://***/product/list/22/foo
* will be matched by this route, and result:
*
* [module] =>
* [controller] => product
* [action] => info
* [method] => GET
* [params:protected] => Array
* (
* [id] => 22
* [name] => foo
* )
*
*/
$route = new Yaf_Route_Rewrite(
"/product/list/:id/:name",
array(
"controller" => "product",
"action" => "info",
)
);
$router->addRoute('dummy', $route);
}
?>
See Also
- Yaf_Router::addConfig() - Add config-defined routes into Router
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Regex
- Yaf_Route_Rewrite
- Yaf_Route_Map
- 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