下面这个路由的写法如何理解

WBOY
Release: 2016-06-23 13:13:55
Original
1040 people have browsed it

/**
* 控制器调度
*
*/
private static function control(){
//二级域名
if ($GLOBALS['setting_config']['enabled_subdomain'] == '1' && $_GET['act'] == 'index' && $_GET['op'] == 'index'){
$store_id = subdomain();
if ($store_id > 0) $_GET['act'] = 'show_store';
}
$act_file = realpath(BASE_PATH.'/control/'.$_GET['act'].'.php');
$class_name = $_GET['act'].'Control';
if (!@include($act_file)){
   if (C('debug')) {
       throw_exception("Base Error: access file isn't exists!");
   } else {
       showMessage('抱歉!您访问的页面不存在','','html','error');
   }
}
if (class_exists($class_name)){
$main = new $class_name();
$function = $_GET['op'].'Op';
if (method_exists($main,$function)){
$main->$function();
}elseif (method_exists($main,'indexOp')){
$main->indexOp();
}else {
$error = "Base Error: function $function not in $class_name!";
throw_exception($error);
}
}else {
$error = "Base Error: class $class_name isn't exists!";
throw_exception($error);
}
}


回复讨论(解决方案)

把get里面的$act和$Op接下来,然后act是控制器的名字,将act接下来之后拼装成$actControl,然后引入文件,引入文件失败就抛异常,找到文件之后判断是否有$OpOp这个方法,如果没有就调用indexOp方法,如果还是没有就抛出方法不存在异常

发代码段能不能用代码格式啊= =看的头疼。。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template