ecmall是一个基于mvc模式框架系统,跟thinkphp有点像。先从ecmall的入口开始,ecmall入口文件upload/index.php、admin.php:javascript
index.php启动ecmall前台,启动后则进入ecmall框架核心文件ecmall.php. ecmall.php至关于一个调度中心,接收不一样的控制命令(app)以及命令的相关操做(funciton),接着对其进行分配处理。而后调度中心把这些命令(app)和方法(function) 传到前台控制中心对应的具体控制器上。"控制器"接收到命令后,开始实施执行控制,接着把处理后的结果传给view模板文件(模板命名规则:appname.fucname.html)。php
其中控制器接收到命令执行过程当中,能够调用调度中心的模型获取方法&m()实例化一个模型,进行数据的curd操做。html
index.php:前端
01 |
include (ROOT_PATH . '/eccore/ecmall.php' ); |
03 |
ECMall::startup( array ( |
04 |
'default_app' => 'default' , |
05 |
'default_act' => 'index' , |
06 |
'app_root' => ROOT_PATH . '/app' , |
08 |
'external_libs' => array ( |
09 |
ROOT_PATH . '/includes/global.lib.php' , |
10 |
ROOT_PATH . '/includes/libraries/time.lib.php' , |
11 |
ROOT_PATH . '/includes/ecapp.base.php' , |
12 |
ROOT_PATH . '/includes/plugin.base.php' , |
13 |
ROOT_PATH . '/app/frontend.base.php' , |
ecmall.php:java
04 |
function startup( $config = array ()) |
07 |
require (ROOT_PATH . '/eccore/controller/app.base.php' ); //基础控制器类 |
08 |
require (ROOT_PATH . '/eccore/model/model.base.php' ); //模型基础类 |
10 |
if (!emptyempty( $config [ 'external_libs' ])) |
12 |
foreach ( $config [ 'external_libs' ] as $lib ) |
18 |
if (!get_magic_quotes_gpc()) |
20 |
$_GET = addslashes_deep( $_GET ); |
21 |
$_POST = addslashes_deep( $_POST ); |
22 |
$_COOKIE = addslashes_deep( $_COOKIE ); |
26 |
$default_app = $config [ 'default_app' ] ? $config [ 'default_app' ] : 'default' ; |
27 |
$default_act = $config [ 'default_act' ] ? $config [ 'default_act' ] : 'index' ; |
29 |
$app = isset( $_REQUEST [ 'app' ]) ? trim( $_REQUEST [ 'app' ]) : $default_app ; |
30 |
$act = isset( $_REQUEST [ 'act' ]) ? trim( $_REQUEST [ 'act' ]) : $default_act ; |
32 |
$app_file = $config [ 'app_root' ] . "/{$app}.app.php" ; |
33 |
if (! is_file ( $app_file )) |
35 |
exit ( 'Missing controller' ); |
41 |
$app_class_name = ucfirst( $app ) . 'App' ; |
44 |
$app = new $app_class_name (); |
46 |
$app ->do_action( $act ); //转发至对应的Action |
51 |
//根据app后面所跟的参数,来判断加载对应的控制器类文件,类文件在app文件夹下,对应名称与参数相同,act后面的参数是对应控制器中的操做方法处理请求 |
52 |
//而对应的动做中,会有一个判断: if (!IS_POST){请求前的页面内容的显示}else{请求后的表单处理及处理完成后的页面跳转}。其中包括使用json处理数据 |
54 |
$this ->assign( 'order' , $order_info ); //向模板页传递所须要参数的值 |
55 |
$this ->display( 'buyer_order.confirm.html' ); //跳转到哪一个页面 |
56 |
$this ->json_result( $new_data , 'confirm_order_successed' ); //使用json的方式传递参数,而后在页面上使用javascript处理请求的跳转 |
因为这个机制,ECMALL中能够自行添加APP,模块,插件等。如何在ECMALL中添加本身的APP呢?好比访问地址为http://xxx.com/index.php?app=hellothinkphp
- 在ecmall的app目录下创建一个新的名称为hello.app.php的应用文件
- 在languages的sc-utf8的目录下创建对应的语言文件 hello.lang.php ,并返回数组 (若不创建,会出错)
- hello.app.php中的类为HelloApp,并继承FrontendApp
- 此为前端程序,在ecmall的themes/mall/default文件夹下创建一个hello.index.html模板文件
- 重写默认的index方法,可使用模板的方式输出:
3 |
$this ->display( 'hello.index.html' ); |
- 编写其余方法好比访问地址为http://xxx.com/index.php?app=hello&act=test
这个URL访问的名为hello的app类中的test方法,其实http://xxx.com/index.php?app=hello默认访问的是index方法。json
01 |
//一、在upload/app/下创建一个test.app.php |
03 |
class TestApp extends MallbaseApp |
05 |
public function index() |
08 |
$uc_first = ucfirst( $str ). '<br>' ; |
09 |
$uc_words =ucwords( $str ). '<br>' ; |
16 |
$this ->assign( 'ss' , $uc_first ); |
17 |
$this ->assign( 'sss' , $uc_words ); |
18 |
$this ->display( 'test.index.html' ); |
23 |
//二、在upload/languages/sc-utf-8/下创建一个test.lang.php |
28 |
// 三、在upload/themes/mall/default/创建一个test.index.html |
admin.php这是启动ecmall后台。启动后也进入ecmall框架核心文件ecmall.php。以后的操做跟前台差很少,区别是调度中心把命令传给"后台"控制中心。但控制器调用的模型是同一个模型中心。数组