©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
(Yaf >=1.0.0)
Yaf_Route_Regex::__construct — The __construct purpose
$match
, array $route
[, array $map
[, array $verify
]] )
match
一个完整的正则表达式,用来匹配一个请求的uri,如果不能匹配,Yaf_Route_Regex 将返回FALSE。
route
当路由正则匹配成功请求uri时,Yaf_Route_Regex将会用它来决定哪一个m/c/a被路由。
在这个数组中无论是m/c/a都是最优的,如果你没有提供一个明确的值,它将会以默认方式被路由。 另外, 你也可以使用map的结果作为m/c/a的结果.
map
将匹配到的结果捕捉放到一个已经命名好的数组中。
verify
Example #1 Yaf_Route_Regex() example
<?php
Yaf_Dispatcher :: getInstance ()-> getRouter ()-> addRoute ( "name" ,
new Yaf_Route_Regex (
"#^/product/([^/]+)/([^/])+#" , //match request uri leading "/product"
array(
'controller' => "product" , //route to product controller,
),
array(
1 => "name" , // now you can call $request->getParam("name")
2 => "id" , // to get the first captrue in the match pattern.
)
)
);
?>
Example #2 Yaf_Route_Regex(as of 2.3.0)() example
<?php
Yaf_Dispatcher :: getInstance ()-> getRouter ()-> addRoute ( "name" ,
new Yaf_Route_Regex (
"#^/product/([^/]+)/([^/])+#" , //match request uri leading "/product"
array(
'controller' => ":name" , //使用上面匹配的:name, 也就是$1作为controller
),
array(
1 => "name" , // now you can call $request->getParam("name")
2 => "id" , // to get the first captrue in the match pattern.
)
)
);
?>
Example #3 Yaf_Route_Regex() example
<?php
$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(
1 => "uri" , // now you can call $request->getParam("uri")
),
),
);
Yaf_Dispatcher :: getInstance ()-> getRouter ()-> addConfig (
new Yaf_Config_Simple ( $config ));
?>