Home >Backend Development >PHP Tutorial >Basics of ecshop from scratch (17)_PHP tutorial

Basics of ecshop from scratch (17)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:17:13825browse

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.

Typical frameworks: ThinkPHP, Yii, Ci, Zend-framework, symphony

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
3
4
5
6
7
8
9
            >}
2
3
4
5
6
7
8
9
  >}

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
3
4
5

2
3
4
5

2
Deny from All

2
Deny from All

2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
                $rows = $db->fetchAll($sql);
}
                $rows = $db->fetchAll($sql);
}

2
3
4
5
6
7
8
9
10
11
12
13
14
>


    
    "      
    
"    
    

    

    
2
3
4
5
6
7
8
9
10
11
12
13
14



    
    "      
    "    
    

    

    

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
                    }
}
                    }
}

2
3
4
5
6
7
8
9
10
11
12
13
//
//$model_match = new MatchModel;
$rows = $model_match->getlist>

2
3
4
5
6
7
8
9
10
11
12
13

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
>


    
    "      
    
"    

    
"
    

    
>



"

"
span>

2
3
4
5
6
7
8
9
10
11
12
$model_match = new MatchModel;
$model_match->delbyid>

2
3
4
5
6
7
8
9
10
11
12

span>

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
     *      *
     * @param $match_id
     *
     * @return bool
     */            
        
        
            }
     *      *
     * @param $match_id
     *
     * @return bool
     */            
        
        
            }

2
3
4
5
6
7
* */
}

2
3
4
5
6
7

* */  
 }

2
3
4
5
6
7
8
9

*
*/
}

2
3
4
5
6
7
8
9

* */  
 }

2
3
4
5
6
7
8
9

>    }
 }

2
3
4
5
6
7
8
9
    }
 }

2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
    }
                        }
 }
    }
                        }
 }

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
     *      *
     * @param $match_id
     *
     * @return bool
     */            
        
        
        
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
     *      *
     * @param $match_id
     *
     * @return bool
     */            
        
        
        

2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
>    
    "      
    
"    
    

    

    
>
"
"
                                                                                                                            span> span> span>

Controller, controller

2
3
4
5
6
7
8
9
//

2
3
4
5
6
7
8
9

//

2

2
2
3
4
5
    }    }

2
3
4
5
>} >}

Just execute the correct controller code in the corresponding part:

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        $model_match = new MatchModel;
    $rows = $model_match->getList();
    

        $model_match = new MatchModel;
    $model_match->delById(    
}
> $model_match = new MatchModel;
$rows = $model_match->getList();
}
span> > $model_match = new MatchModel;
$model_match->delById( 
span>} 2
3
4
5
6
>
//
2
3
4
5
6
>
//
span>

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
* */ * */ }

*
*/ }
}

* */   * */                                                       > }
}
< /span>

2
3
4
5
6
7
8
9
10
11

//$action = $a.//>

2
3
4
5
6
7
8
9
10
11

2
3
4
5
6
            }
}
span // }
}

2
3
4
5
6
7
    }
}

2
3
4
5
6
7


    
    
    

2
3
4
5
6





2
3
4
5
6

Test: localhost/six/index.php?c=Student&a=list localhost/six/index.php?c=Match&a=list

2
3

header(
2
3

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
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
    /index.php   入口文件
    /application 应用程序目录
        /model      模型类目录
        /view       视图类目录
        /controller 控制器类目录
    /framework   框架代码目录
        /Model.        /MySQLDB.class.php  mysql数据库的操作类        
/index.php Entry File
/application Application Directory
/model /Model Class Directory
/view /View Class Directory
/controller Controller class directory
/framework Framework code directory
/Model. /MySQLDB.class.php MySQL database operation class 

http://www.bkjia.com/PHPjc/626634.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/626634.htmlTechArticleGoal: Case (project) developed based on customized mvc framework Typical business logic: E-commerce: Mall ( Jingdong), B2C, C2C (Taobao), group buying, flash sales, purchasing agency content management: new...