(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
/**
* 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(
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
/**
* ʹ�ö�̬��controller
*/
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
/**
* 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(
1 => "uri", // now you can call $request->getParam("uri")
),
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
?>