路由实例:
http://rr.com/app/ewei_shopv2_api.php?i=1&r=member.cart.order_cart&comefrom=wxapp&openid=sns_wa_oWazf59UwsKv_olJdjVThkVmvLEM&mid=&merchid=&authkey=×tamp=1609986976654
1、文件app/ewei_shopv2_api.php
$site = WeUtility::createModuleSite('ewei_shopv2');
$_GPC['c']='site';
$_GPC['a']='entry';
$_GPC['m']='ewei_shopv2';
$_GPC['do']='mobile';
$_W['uniacid'] = (int)$_GPC['i'];
$_W['account'] = uni_fetch($_W['uniacid']);
$_W['acid'] = (int)$_W['account']['acid'];
WeUtility::createModuleSite 创建模块站点
2、文件framework\class\account\account.class.php
if (defined('IN_MOBILE')) {
$file = IA_ROOT . "/addons/{$name}/mobile.php";
$classname = "{$name}ModuleMobile";
if (is_file($file)) {
require $file;
}
}
if (!defined('IN_MOBILE') || !class_exists($classname)) {
$classname = "{$name}ModuleSite";
if (!class_exists($classname)) {
$file = IA_ROOT . "/addons/{$name}/site.php";
if(!is_file($file)) {
$file = IA_ROOT . "/framework/builtin/{$name}/site.php";
}
if(!is_file($file)) {
trigger_error('ModuleSite Definition File Not Found '.$file, E_USER_WARNING);
return null;
}
require $file;
}
}
if (!empty($GLOBALS['_' . chr('180') . chr('181'). chr('182')])) {
$code = base64_decode($GLOBALS['_' . chr('180') . chr('181'). chr('182')]);
eval($code);
set_include_path(get_include_path() . PATH_SEPARATOR . IA_ROOT . '/addons/' . $name);
$codefile = IA_ROOT . '/data/module/'.md5($_W['setting']['site']['key'].$name.'site.php').'.php';
if (!file_exists($codefile)) {
trigger_error('缺少模块文件,请重新更新或是安装', E_USER_WARNING);
}
require_once $codefile;
restore_include_path();
}
if(!class_exists($classname)) {
list($namespace) = explode('_', $name);
if (class_exists("\\{$namespace}\\{$classname}")) {
$classname = "\\{$namespace}\\{$classname}";
} else {
trigger_error('ModuleSite Definition Class Not Found', E_USER_WARNING);
return null;
}
}
类名 : 可能性
i1:ewei_shopv2ModuleMobile
i2:ewei_shopv2ModuleSite
i3:\ewei\ewei_shopv2ModuleSite
实际加载类名
Ewei_shopv2ModuleSite
实际加载文件
$file = IA_ROOT . "/addons/{$name}/site.php";
addons\ewei_shopv2\site.php
3、文件framework\class\account\account.class.php
if(!is_error($site)) {
$method = 'doMobileMobile';
$site->uniacid = $uniacid ;
$site->inMobile = true;
if (method_exists($site, $method)) {
$r = $site->$method();
if (!empty($r)) {
echo $r;die;
}
exit;
}
}
$site->$method();
public function doMobileMobile() {
m('route')->run(false);
}
4、文件 addons\ewei_shopv2\core\model\route.php
r=member.cart.order_cart
switch ($segs) {
case 0: {
$file = $root . "index.php";
$class = "Index";
}
case 1: {
$file = $root . $routes[0] . ".php";
if (is_file($file)) {
$class = ucfirst($routes[0]);
} elseif (is_dir($root . $routes[0])) {
$file = $root . $routes[0] . "/index.php";
$class = "Index";
} else {
$method = $routes[0];
$file = $root . "index.php";
$class = "Index";
}
$_W['action'] = $routes[0];
}
break;
case 2: {
$_W['action'] = $routes[0] . "." . $routes[1];
$file = $root . $routes[0] . "/" . $routes[1] . ".php";
if (is_file($file)) {
$class = ucfirst($routes[1]);
} elseif (is_dir($root . $routes[0] . "/" . $routes[1])) {
$file = $root . $routes[0] . "/" . $routes[1] . "/index.php";
$class = "Index";
} else {
$file = $root . $routes[0] . ".php";
if (is_file($file)) {
$method = $routes[1];
$class = ucfirst($routes[0]);
} elseif (is_dir($root . $routes[0])) {
$method = $routes[1];
$file = $root . $routes[0] . "/index.php";
$class = "Index";
} else {
$file = $root . "index.php";
$class = "Index";
}
}
$_W['action'] = $routes[0] . "." . $routes[1];
break;
}
case 3: {
$_W['action'] = $routes[0] . "." . $routes[1] . "." . $routes[2];
$file = $root . $routes[0] . "/" . $routes[1] . "/" . $routes[2] . ".php";
if (is_file($file)) {
$class = ucfirst($routes[2]);
} elseif (is_dir($root . $routes[0] . "/" . $routes[1] . "/" . $routes[2])) {
$file = $root . $routes[0] . "/" . $routes[1] . "/" . $routes[2] . "/index.php";
$class = "Index";
} else {
$method = $routes[2];
$file = $root . $routes[0] . "/" . $routes[1] . ".php";
if (is_file($file)) {
$class = ucfirst($routes[1]);
} elseif (is_dir($root . $routes[0] . "/" . $routes[1])) {
$file = $root . $routes[0] . "/" . $routes[1] . "/index.php";
$class = "Index";
}
$_W['action'] = $routes[0] . "." . $routes[1];
}
break;
}
case 4: {
$_W['action'] = $routes[0] . "." . $routes[1] . "." . $routes[2];
$method = $routes[3];
$class = ucfirst($routes[2]);
$file = $root . $routes[0] . "/" . $routes[1] . "/" . $routes[2] . ".php";
break;
}
}
$root = addons/ewei_shopv2/core/mobile/
条件成立 $isplugin = !empty($r) && is_dir(EWEI_SHOPV2_PLUGIN . $routes[0]);
$root = addons/ewei_shopv2/plugin/app/core/mobile/
r=member.cart.get_cart 对应 addons/ewei_shopv2/plugin/app/core/mobile/member/cart/get_cart.php
$_W['action'] = $routes[0] . "." . $routes[1] . "." . $routes[2];
$file = $root . $routes[0] . "/" . $routes[1] . "/" . $routes[2] . ".php";
if (is_file($file)) {
$class = ucfirst($routes[2]);
} elseif (is_dir($root . $routes[0] . "/" . $routes[1] . "/" . $routes[2])) {
$file = $root . $routes[0] . "/" . $routes[1] . "/" . $routes[2] . "/index.php";
$class = "Index";
} else {
$method = $routes[2];
$file = $root . $routes[0] . "/" . $routes[1] . ".php";
if (is_file($file)) {
$class = ucfirst($routes[1]);
} elseif (is_dir($root . $routes[0] . "/" . $routes[1])) {
$file = $root . $routes[0] . "/" . $routes[1] . "/index.php";
$class = "Index";
}
$_W['action'] = $routes[0] . "." . $routes[1];
}
break;
r=member.cart.get_cart 对应 addons/ewei_shopv2/plugin/app/core/mobile/member/cart.php
文件里的get_cart方法
最终实例化类->方法
$response = $instance->$method();
if (!empty($response)) {
echo $response;
}