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。以後的操做跟前臺差很少,區別是調度中心把命令傳給"後臺"控制中心。但控制器調用的模型是同一個模型中心。數組