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

下面这个方法是起到路由作用的,它是如何完成这个流程的

下面这个方法是起到路由作用的,它是怎么完成这个流程的
/**
* 控制器调度
*
*/
private static function control(){
//二级域名
//var_dump($globals['setting_config']['enabled_subdomain']);
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';
//echo $act_file;
if ([email protected]($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);
}
}
------解决思路----------------------
根据controler与action,判断要调用的类与方法
$act_file = realpath(base_path.'/control/'.$_get['act'].'.php');
$class_name = $_get['act'].'control';

然后判断如果类和方法存在则调用,就这样。
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);
}
}

其它类似信息

推荐信息