问一个关于URL模式匹配的问题
我想做一个由用户灵活配置的URI程序,也就是说有三个域(暂且这么说吧){action},{method},{params},可以随意组合成一个URI,当然每个域只出现一次或0次,{action}、{method}可由字母下划线组成,{params}可以由URL支持的字符组成。具体如下:
1. /{action}/{method}/{params}
e.g: /product/list/p/2
2. /{action}_{method}_{params}
e.g: /product_list_p2
3. /{action}-{method}-{params}
e.g: /product-list-p2
4. /{action}_{method}_{params}.(html|htm)
e.g: /product_list_p2.html
5. /{action}-{method}-{params}.(html|htm)
e.g: /product-list-p2.html
6. /{action}/{method}-{params}
e.g: /product/list-p2
7. /{action}/{method}?{params}
e.g: /product/list?p=2&_t=19383938439
8. etc.
简单描述: {action}、{method}不言而喻就是分别映射到Action类和Action类中的方法,{params}主要是用get方法提交的参数。
我想问的是,有没有什么好的方法实现?大家一起来讨论讨论哈! THINKPHP是这样写的
$paths = explode($depr,trim($_SERVER['PATH_INFO'],'/'));
if(C('VAR_URL_PARAMS')) {
// 直接通过$_GET['_URL_'] $_GET['_URL_'] 获取URL参数 方便不用路由时参数获取
$_GET =$paths;
}
$var=array();
if (C('APP_GROUP_LIST') && !isset($_GET)){
$var = in_array(strtolower($paths),explode(',',strtolower(C('APP_GROUP_LIST'))))? array_shift($paths) : '';
if(C('APP_GROUP_DENY') && in_array(strtolower($var),explode(',',strtolower(C('APP_GROUP_DENY'))))) {
// 禁止直接访问分组
exit;
}
}
if(!isset($_GET)) {// 还没有定义模块名称
$var= array_shift($paths);
}
$var= array_shift($paths);
页:
[1]