Yaf_Router::addRoute
Yaf_Router::addRoute
(Yaf >=1.0.0)
Yaf_Router::addRoute - 将新路由添加到路由器中
描述
public bool Yaf_Router::addRoute ( string $name , Yaf_Route_Abstract $route )
默认情况下,Yaf_Router使用Yaf_Route_Static作为其默认路由。您可以通过调用此方法将新路由添加到路由器的路由堆栈中。
较新的路由将在较旧的(路由堆栈)之前被调用,并且如果较新的路由器返回TRUE
,路由器进程将结束。否则,较旧的将被调用。
参数
该函数没有参数。
返回值
示例
示例#1
Yaf_Dispatcher::autoRender()示例
<?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
}
?>
另请参阅
- Yaf_Router::addConfig() - 将配置定义的路由添加到路由器中
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Regex
- Yaf_Route_Rewrite
- Yaf_Route_Map
← Yaf_Router::addConfig
Yaf_Router::__construct →