Home >Backend Development >PHP Tutorial >ECMall requests and system jumps_PHP tutorial

ECMall requests and system jumps_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:33:551068browse

ecmall is a framework system based on mvc pattern, which is somewhat similar to thinkphp. Let’s start with the ecmall entrance, ecmall entrance files upload/index.php, admin.php:

index.php starts the ecmall frontend, and after startup, it enters the ecmall framework core file ecmall.php. ecmall.php is equivalent to a dispatch center, receiving different control commands (app) and command-related operations (funciton), and then It performs allocation processing. Then the dispatch center transmits these commands (app) and methods (function) to the specific controller corresponding to the front-end control center. After receiving the command, the "controller" starts to implement execution control, and then passes the processed results to the view template file (template naming rule: appname.fucname.html).

When the controller receives the command and executes it, it can call the model acquisition method &m() of the dispatch center to instantiate a model and perform curd operations on the data.

index.php:

include(ROOT_PATH . '/eccore/ecmall.php');  
/* 启动ECMall */  
ECMall::startup(array(  
    'default_app'   =>  'default',  
    'default_act'   =>  'index',  
    'app_root'      =>  ROOT_PATH . '/app',  
//加载系统所需要的基础类  
    'external_libs' =>  array(  
        ROOT_PATH . '/includes/global.lib.php',  
        ROOT_PATH . '/includes/libraries/time.lib.php',  
        ROOT_PATH . '/includes/ecapp.base.php',  
        ROOT_PATH . '/includes/plugin.base.php',  
        ROOT_PATH . '/app/frontend.base.php',  
    ),  
));  

ecmall.php:

class ECMall  
{  
    /* 启动 */  
    function startup($config = array())  
    {  
        /* 加载初始化文件 */  
        require(ROOT_PATH . '/eccore/controller/app.base.php');     //基础控制器类  
        require(ROOT_PATH . '/eccore/model/model.base.php');   //模型基础类  
  
        if (!emptyempty($config['external_libs']))  
        {  
            foreach ($config['external_libs'] as $lib)  
            {  
                require($lib);  
            }  
        }  
        /* 数据过滤 */  
        if (!get_magic_quotes_gpc())  
        {  
            $_GET   = addslashes_deep($_GET);  
            $_POST  = addslashes_deep($_POST);  
            $_COOKIE= addslashes_deep($_COOKIE);  
        }  
  
        /* 请求转发 */  
        $default_app = $config['default_app'] ? $config['default_app'] : 'default';  
        $default_act = $config['default_act'] ? $config['default_act'] : 'index';  
  
        $app    = isset($_REQUEST['app']) ? trim($_REQUEST['app']) : $default_app;  
        $act    = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : $default_act;  
  
        $app_file = $config['app_root'] . "/{$app}.app.php";  
        if (!is_file($app_file))  
        {  
            exit('Missing controller');  
        }  
  
        require($app_file);  
        define('APP', $app);  
        define('ACT', $act);  
        $app_class_name = ucfirst($app) . 'App';  
  
        /* 实例化控制器 */  
        $app     = new $app_class_name();  
        c($app);  
        $app->do_action($act);        //转发至对应的Action  
        $app->destruct();  
    }  
}  
  
//根据app后面所跟的参数,来判断加载对应的控制器类文件,类文件在app文件夹下,对应名称与参数相同,act后面的参数是对应控制器中的操作方法处理请求  
//而对应的动作中,会有一个判断: if (!IS_POST){请求前的页面内容的显示}else{请求后的表单处理及处理完成后的页面跳转}。其中包括使用json处理数据  
//这里需要提出的是:在控制器中:   
$this->assign('order', $order_info);      //向模板页传递所需要参数的值       
$this->display('buyer_order.confirm.html');//跳转到哪个页面  
$this->json_result($new_data, 'confirm_order_successed');//使用json的方式传递参数,然后在页面上使用javascript处理请求的跳转 

Due to this mechanism, APPs, modules, plug-ins, etc. can be added to ECMALL by yourself. How to add your own APP in ECMALL? For example, the access address is http://xxx.com/index.php?app=hello

  1. Create a new application file named hello.app.php in the app directory of ecmall
  2. Create the corresponding language file hello.lang.php in the sc-utf8 directory of languages, and return an array (if not created, an error will occur)
  3. The class in hello.app.php is HelloApp and inherits FrontendApp
  4. This is a front-end program. Create a hello.index.html template file in the themes/mall/default folder of ecmall
  5. Override the default index method and use template output:
  6. $h = "Hello";  
        $this->assign("h",$h);  
        $this->display('hello.index.html');  
    
  7. Write other methods such as access address http://xxx.com/index.php?app=hello&act=test

This URL accesses the test method in the app class named hello. In fact, http://xxx.com/index.php?app=hello accesses the index method by default.

//1、在upload/app/下建立一个test.app.php  
<?php  
class TestApp extends MallbaseApp  
{  
	public function index()  
	{  
		$str="hello world";  
		$uc_first= ucfirst($str).'<br>';  
		$uc_words=ucwords($str).'<br>';  
           
    	$Model=&m('goods');  
    	$res=$Model->get(27);  
   		print_r($res);  
       
       
     	$this->assign('ss',$uc_first);  
    	$this->assign('sss',$uc_words);  
     	$this->display('test.index.html');   
	}  
}     
?>  
   
//2、在upload/languages/sc-utf-8/下建立一个test.lang.php  
<?php  
	return array();             
?>  
   
//  3、在upload/themes/mall/default/建立一个test.index.html  

admin.php This is to start the ecmall background. After startup, also enter the ecmall framework core file ecmall.php. The subsequent operations are similar to those at the front desk. The difference is that the dispatch center passes the command to the "backstage" control center. But the model called by the controller is the same model center.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752396.htmlTechArticleecmall is a framework system based on mvc mode, which is somewhat similar to thinkphp. Let’s start with the ecmall entrance. The ecmall entrance files upload/index.php and admin.php: index.php starts the ecmall front desk and starts...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn