(Yaf >=1.0.0)
Yaf_Route_Rewrite::__construct — The __construct purpose
$match
, array $route
[, array $verify
] )
match
一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷式锟斤拷锟结被锟斤拷锟斤拷匹锟斤拷一锟斤拷锟斤拷锟斤拷锟絬ri锟斤拷锟斤拷锟狡ワ拷锟绞э拷埽锟�Yaf_Route_Rewrite 锟结返锟斤拷FALSE锟斤拷
route
锟斤拷路锟斤拷锟斤拷锟斤拷匹锟斤拷晒锟斤拷锟斤拷锟絬ri时锟斤拷Yaf_Route_Rewrite 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷m/c/a锟斤拷路锟缴★拷
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟絤/c/a锟斤拷锟斤拷锟斤拷锟脚的o拷锟斤拷锟斤拷锟矫伙拷锟斤拷峁┮伙拷锟斤拷锟饺凤拷锟街碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥拷戏锟绞斤拷锟铰凤拷伞锟�
verify
Example #1 Yaf_Route_Rewrite()example
<?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 )
Example #2 Yaf_Route_Rewrite()example
<?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, )
Example #3 Yaf_Route_Rewrite(as of 2.3.0)()example
<?php
/**
* 使锟矫讹拷态锟斤拷锟斤拷锟轿猘ction锟斤拷
*/
$config = array(
"name" => array(
"type" => "rewrite", //Yaf_Route_Rewrite route
"match" => "/user-list/:a/:id", //match only /user-list/锟斤拷头锟斤拷
"route" => array(
'controller' => "user", //route to user controller,
'action' => ":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, )