您好,欢迎访问一九零五行业门户网

简单的url路由控制[PHP]

无详细内容 无 define('base_path', dirname(__file__).directory_separator);//系统根目录define('module_path', base_path.'modules'.directory_separator);//模块目录 $module = empty($_get['m']) ? '' : strtolower($_get['m']); //文件夹$control = emp
define('base_path', dirname(__file__).directory_separator);//系统根目录define('module_path', base_path.'modules'.directory_separator);//模块目录 $module = empty($_get['m']) ? '' : strtolower($_get['m']); //文件夹$control = empty($_get['c'])? 'index' : strtolower($_get['c']); //文件{类}$action = empty($_get['a'])? 'index' : strtolower($_get['a']); //方法 if($module){ $controlfile = module_path . $module . directory_separator . $control . '.php'; if( !file_exists($controlfile) ) echo $module . directory_separator . $control . '.php'.'类文件不存在'; exit(); include($controlfile); $c = new $control; if( !method_exists($c, $action) ) echo $c.'方法不存在'; exit(); $c->$action();}else{ //默认首页[可用smarty模板引擎加载视图] $smarty->display('index.html');}/**写了个简单的路由控制功能,根据参数m,c,a,控制响应url的模块,文件,方法。(mvc)方式url。说明:mvc方式,m模块[对应模块文件夹],c控制器[对应类文件],a方法[对应对象方法]没有指定module时默认访问系统首页没有指定control时默认访问index[文件|类],没有该文件时输出文件[类]不存在错误没有指定action时默认访问index[方法],没有该方法时输出方法不存在错误例如:http://www.xxx.com/web/index.php?m=admin访问 module下admin文件夹下的index文件(类名与文件名相同)下的index方法*/
其它类似信息

推荐信息