• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-23) 20次浏览 已收录 0个评论
文章目录[隐藏]

/**
* 控制器调度
*
*/
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_exis·本2文来源gaodai$ma#com搞$代*码网2搞gaodaima代码ts($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方法,如果还是没有就抛出方法不存在异常

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:下面这个路由的写法如何理解
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址