Yaf_Router::addRoute

(Yaf >=1.0.0)

Yaf_Router::addRoute往Router中添加新的路由

说明

public Yaf_Router::addRoute ( string $name , Yaf_Route_Abstract $route ) : Yaf_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);
    }
?>