随便举个栗子
https://ssl.infowei.com/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=get_recommand&page=1&merchid=0&_=1568885489792
从链接可以看到访问的是/app/index.php
i(uniacid)->2
controller ->entry
module->ewei_shopv2
r->get_recommand
首先来看/app/index.php这个文件
1.初始化了框架
2.一直到最后controller 都是entry 然后运行_forward, 然后我们跟着forward找到$file(/app/source/entry/site.ctrl.php)
在执行__init.php之前 action 参数是空
$init = IA_ROOT . "/app/source/{$controller}/__init.php";
if(is_file($init)) {
require $init;
}
然后/app/source/entry/__init.php里
if (empty($action)) {
$action = 'site';
}
然后我们就获取到了action,用来在下面拼接file的路径(/app/source/entry/site.ctrl.php)
我不是太确定在这里是如何执行site.ctrl.php的, 追踪的时候发现require之后会直接执行site.ctrl.php
ok先不管 继续往下走
require _forward($controller, $action);
function _forward($c, $a) {
$file = IA_ROOT . '/app/source/' . $c . '/' . $a . '.ctrl.php';
return $file;
}
3.在site.ctrl.php会执行$site->$method()
在这里
$site->ewei_shopv2(这个应用)
$method->doMobileMobile
它会直接执行到/addons/ewei_shopv2/site.php 的 doMobileMobile方法
<?php
/**
* [WeEngine System] Copyright (c) 2014 WE7.CC
* WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
*/
defined('IN_IA') or exit('Access Denied');
if (!empty($_W['uniacid'])) {
$link_uniacid = table('uni_link_uniacid')->getMainUniacid($_W['uniacid'], $entry['module']);
if (!empty($link_uniacid)) {
$_W['uniacid'] = $link_uniacid;
$_W['account']['link_uniacid'] = $link_uniacid;
}
}
$site = WeUtility::createModuleSite($entry['module']);
if(!is_error($site)) {
$do_function = $site instanceof WeModuleSite ? 'doMobile' : 'doPage';
$method = $do_function . ucfirst($entry['do']);
exit($site->$method());
}
exit();
require_once IA_ROOT . '/addons/ewei_shopv2/version.php';
require_once IA_ROOT . '/addons/ewei_shopv2/defines.php';
require_once EWEI_SHOPV2_INC . 'functions.php';
class Ewei_shopv2ModuleSite extends WeModuleSite
{
public function getMenus()
{
global $_W;
return array(
array('title' => '管理后台', 'icon' => 'fa fa-shopping-cart', 'url' => webUrl())
);
}
public function doWebWeb()
{
m('route')->run();
}
public function doMobileMobile()
{
m('route')->run(false);
}
public function payResult($params)
{
return m('order')->payResult($params);
}
}
4.跟踪m()方法到 /addons/ewei_shopv2/core/inc/functions.php
if (!function_exists('m')) {
function m($name = '')
{
static $_modules = array();
if (isset($_modules[$name])) {
return $_modules[$name];
}
$model = EWEI_SHOPV2_CORE . "model/" . strtolower($name) . '.php';
if (!is_file($model)) {
die(' Model ' . $name . ' Not Found!');
}
require_once $model;
$class_name = ucfirst($name) . "_EweiShopV2Model";
$_modules[$name] = new $class_name();
return $_modules[$name];
}
}
5.执行到了/addons/ewei_shopv2/core/model/route.php 的run方法
方法很长我没有仔细去看 我们的路由参数只有一段 所以直接进入这里
case 0:
$file = $root . 'index.php';
$class = 'Index';
case 1:
$file = $root . $routes[0] . '.php';
if (is_file($file)) {
$class = ucfirst($routes[0]);
}
else if (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;
最后执行到这里 $instance是Index_EweiShopV2Page的实例 $method是get_recommand
include $file;
$class = ucfirst($class) . '_EweiShopV2Page';
$instance = new $class();
if (!method_exists($instance, $method)) {
show_message('控制器 ' . $_W['controller'] . ' 方法 ' . $method . ' 未找到!');
}
$instance->$method();
exit();
$file-> /addons/ewei_shopv2/core/mobile/index.php
文件的类名就是“Index_EweiShopV2Page”
6.在index.php里可以找到function
function get_recommand(){
global $_W, $_GPC;
$args = array(
'page' => $_GPC['page'],
'pagesize' => 6,
'isrecommand' => 1,
'order' => 'displayorder desc,createtime desc',
'by' => ''
);
$recommand = m('goods')->getList($args);
show_json(1,array('list'=>$recommand['list'], 'pagesize'=>$args['pagesize'], 'total'=>$recommand['total'], 'page'=>intval($_GPC['page'])));
}