Home Backend Development PHP Tutorial ECMall requests and system jumps_PHP tutorial

ECMall requests and system jumps_PHP tutorial

Jul 13, 2016 am 10:33 AM

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',  
    ),  
));  
Copy after login

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处理请求的跳转 
Copy after login

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');  
    
    Copy after login
  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  
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles