Home >Backend Development >PHP Tutorial >Basics of ecshop from scratch (17)_PHP tutorial
Goal: Case (project) developed based on customized mvc framework
Typical business logic: E-commerce: mall (JD.com), B2C, C2C (Taobao), group buying, flash sale, purchasing agent
Content management: Sina portal, Youku video management, blog post management, Weibo
Forum:
Our needs, product management case! Refer to the basic functional implementation of product management that should appear in ecshop.
ecshop, an e-commerce platform (online mall system) with a very high usage rate.
Upload and copy php source code Create data Basic configuration
Download the source code of ecshop, unzip it, and copy (upload) the upload directory to the web directory: it is recommended to change it to the name of ecshop
Use a browser to access index.php in the ecshop directory. Automatically jump to the installation interface (if you need to reinstall, you can also request this address)
Check the environment, typical needs: mysql extension, gd extension (image processing extension)
Configuration information
Database server part:
Administrator information:
Install test data:
Wait for installation to complete:
Tips: It is recommended to choose PHP5.3X version
Design of data structure
Coding design
Typical coding is divided into two major directions: secondary development and framework-based development.
Secondary development: A development method that makes modifications and upgrades to existing products (business logic has been implemented).
Advantages: fast, common business logic has been implemented.
Disadvantages: Poor customization.
Typical products:
E-commerce: ecshop, ecmall, shopex, zen-cart, oscommerce, Mai Jindou
Content management: dedecms, empirecms, phpcms, drupal, wordpress
Forum: phpwind, discuz
Framework development:
The framework does not implement business logic, only the underlying code.
Advantages: No need to write repeated underlying function code, just use it directly, highly customizable.
Disadvantages: Long cycle time.
PHP code and HTML code appear in the same file.
Typically:
On the top, PHP implements all business logic first, and on the bottom, HTML determines the display style.
Or directly use PHP echo to output the required HTML code.
2 |
>} |
2 | >} |
Separately manage the PHP code responsible for data processing and business logic processing, and the HTML (CSS, JS) responsible for display effect processing.
Typical implementation: Split the relevant parts of HTML responsible for display into independent HTML. After PHP processes the business logic, load the HTML code into the file.
To put it simply, it is to separate the original mixed code into 2 pages. These two pages must be combined to achieve the same effect as the original mixed file.
For example: match_list.html (display) match_list.php (logic) require './match_list.html';
template: see match_list.html
Use html related code to display the structure, and use dynamic code php to display data. This type of file is called a template file in the project.
Requirement: Browser user requests must request PHP files responsible for logical functions.
How to restrict browser users from requesting html template files?
Two typical implementation methods:
2 |
2 |
2 |
2 |
2 | Deny from All |
2 |
2 |
} $rows = $db->fetchAll($sql); } |
2 |
> " " |
2 |
" " |
2 |
2 |
} } |
2 |
// //$model_match = new MatchModel; $rows = $model_match->getlist> |
2 |
|
2 |
2 |
> " " " |
2 |
$model_match = new MatchModel; $model_match->delbyid> |
2 |
span> |
2 |
2 |
* * * @param $match_id * * @return bool */ } |
2 |
* */ } |
2 | * */ } |
2 | * */ } |
2 | > } } |
2 |
} } |
2 |
2 |
} } } |
2 |
* * * @param $match_id * * @return bool */ |
2 |
* * * @param $match_id * * @return bool */ |
2 |
2 |
> " " |
Controller, controller
2 | // |
2 |
//
|
2
2
2
3
4
5
} }
2 | >} >} |
Just execute the correct controller code in the corresponding part:
2 |
2 |
$model_match = new MatchModel; $rows = $model_match->getList(); } $model_match = new MatchModel; $model_match->delById( } |
2 |
> // |
2 |
> // span> |
2 |
2 |
* */ * */ } * */ } } |
2 | //$action = $a.//> |
2 |
|
2 |
} } |
2 |
|
2 |
|
Test: localhost/six/index.php?c=Student&a=list localhost/six/index.php?c=Match&a=list
2 |
header( |
2 |
header( |
Emphasis:
With a single entry, it is required that all user requests must be requested from the single entry file.
The directory is divided into 2 directories
Reflects the difference between framework code and business logic code
Place the basic model and mysqlDB class definition file in the framework code:
Place the controller, model, and view files corresponding to the business logic in the application directory.
Entry file, usually placed in the site root directory:
Modify the path used in the project
2 |
2 |
/index.php 入口文件 /application 应用程序目录 /model 模型类目录 /view 视图类目录 /controller 控制器类目录 /framework 框架代码目录 /Model. /MySQLDB.class.php mysql数据库的操作类 |