PHP - Manual: Yaf_Router::addRoute
2024-11-15
(Yaf >=1.0.0)
Yaf_Router::addRoute — 往Router中添加新的路由
默认地,Yaf_Router使用Yaf_Route_Static作为它的默认的路由。你可以通过调用这个方法往Router的堆栈中添加一个新的路由
在路由栈中,新的路由规则会比老的规则先调用,如果新路由规则返回TRUE,那么路由进程将会结束。否则,老的规则将会被调用。
本函数还未编写文档,仅有参数列表。
此函数没有参数。
示例 #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);
}
?>