Yaf_Route_Regex
在线手册:中文  英文

Yaf_Route_Regex::__construct

(Yaf >=1.0.0)

Yaf_Route_Regex::__constructThe __construct purpose

说明

public Yaf_Route_Regex::__construct ( string $match , array $route [, array $map [, array $verify ]] )

Warning

本函数还未编写文档,仅有参数列表。

参数

match

A complete Regex pattern, will be used to match a request uri, if doesn't matched, Yaf_Route_Regex will return FALSE.

route

When the match pattern matches the request uri, Yaf_Route_Regex will use this to decide which m/c/a to routed.

either of m/c/a in this array is optianl, if you don't assgian a specific value, it will be routed to default.

map

A array to assign name to the captrues in the match result.

verify

返回值

范例

Example #1 Yaf_Route_Regex()example

<?php
   
/**
    * Add a regex route to Yaf_Router route stack
    */
    
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
        new 
Yaf_Route_Regex(
           
"#^/product/([^/]+)/([^/])+#"//match request uri leading "/product"
           
array(
               
'controller' => "product",  //route to product controller,
           
),
           array(
              
=> "name",   // now you can call $request->getParam("name")
              
=> "id",     // to get the first captrue in the match pattern.
           
)
        )
    );
?>

Example #2 Yaf_Route_Regex()example

<?php
   
/**
    * Add a regex route to Yaf_Router route stack by calling addconfig
    */
    
$config = array(
        
"name" => array(
           
"type"  => "regex",          //Yaf_Route_Regex route
           
"match" => "#(.*)#",         //match arbitrary request uri
           
"route" => array(
               
'controller' => "product",  //route to product controller,
               
'action'     => "dummy",    //route to dummy action
           
),
           
"map" => array(
              
=> "uri",   // now you can call $request->getParam("uri")
           
),
        ),
    );
    
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
        new 
Yaf_Config_Simple($config));
?>

参见


Yaf_Route_Regex
在线手册:中文  英文
易百教程