Yaf_Route_Rewrite::__construct
Yaf_Route_Rewrite::__construct
(Yaf >=1.0.0)
Yaf_Route_Rewrite::__construct - Yaf_Route_Rewrite构造函数
描述
public Yaf_Route_Rewrite::__construct ( string $match , array $route [, array $verify ] )
参数
match
一个模式,将用于匹配一个请求uri,如果它不匹配,Yaf_Route_Rewrite将返回FALSE
。
您可以使用:名称样式来命名匹配的细分受众群,并使用*来匹配剩余的网址细分。
route
当匹配模式匹配请求uri时,Yaf_Route_Rewrite将使用它来决定哪个模块/控制器/动作是目的地。
该数组中的模块/控制器/操作都是可选的,如果您未指定特定值,则会将其路由到默认值。
verify
返回值
示例
示例#1 Yaf_Route_Rewrite()示例
<?php
/**
* Add a rewrite route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_rewrite(
"/product/:name/:id/*", //match request uri leading "/product"
array(
'controller' => "product", //route to product controller,
),
)
?>
上面的例子会输出类似于:
/* for http://yourdomain.com/product/foo/22/foo/bar
* route will result in following values:
*/
array(
"controller" => "product",
"module" => "index", //(default)
"action" => "index", //(default)
)
/**
* and request parameters:
*/
array(
"name" => "foo",
"id" => 22,
"foo" => bar
)
示例#2 Yaf_Route_Rewrite()示例
<?php
/**
* Add a rewrite route to Yaf_Router route stack by calling addconfig
*/
$config = array(
"name" => array(
"type" => "rewrite", //Yaf_Route_Rewrite route
"match" => "/user-list/:id", //match only /user/list/?/
"route" => array(
'controller' => "user", //route to user controller,
'action' => "list", //route to list action
),
),
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config)
?>
上面的例子会输出类似于:
/* for http://yourdomain.com/user-list/22
* route will result in following values:
*/
array(
"controller" => "user",
"action" => "list",
"module" => "index", //(default)
)
/**
* and request parameters:
*/
array(
"id" => 22,
)
示例#3 Yaf_Route_Rewrite(从2.3.0开始)()示例
<?php
/**
* Add a rewrite route use match result as m/c/a name
*/
$config = array(
"name" => array(
"type" => "rewrite",
"match" => "/user-list/:a/:id", //match only /user-list/*
"route" => array(
'controller' => "user", //route to user controller,
'action' => ":a", //route to :a action
),
),
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config)
?>
上面的例子会输出类似于:
/* for http://yourdomain.com/user-list/list/22
* route will result in following values:
*/
array(
"controller" => "user",
"action" => "list",
"module" => "index", //(default)
)
/**
* and request parameters:
*/
array(
"id" => 22,
)
另请参阅
- Yaf_Router::addRoute() - 将新路由添加到路由器中
- Yaf_Router::addConfig() - 将配置定义的路由添加到路由器中
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Regex
- Yaf_Route_Map
← Yaf_Route_Rewrite::assemble
Yaf_Route_Rewrite::route →