Fast Modular development framework (for understanding MVC)

Source: Internet
Author: User
When you write Program Then, when you need to write another program, for example, when you write a message board, you need to write another program Article Management Program. For details, refer to the following figure:
Config. php
Header. Inc. php
Footer. Inc. php
Index. php
Globals. php
.....
The structure of file management programs or other programs can also be like this. Because, if the program is placed on the same website, the configuration is the same. Code At this stage of separation, you need to configure the template engine, and there is a lot of repetitive work to do. If there is a program, you can integrate the previously written programs and maintain the original independence. Programs are independent and integrated. This is what I want to talk about, modular development. This requires a suitable framework.
First, we need to distinguish this framework from the directory structure. For ease of understanding, the main structure is as follows:
Except des/
Modules/
Index. php
Config. php
......
1. Some common class libraries, such as the smarty class library, ADO data class library, or custom class and function library, can be placed under the directory named javasdex, then place these configuration paths in config. PHP File
2. The modules directory is used to store modules, such as the message module. Each module is a directory.
3. Set index. php as the unified program portal.
4. config. php is the global configuration file.
The following is a simple example:
Enter the URL index. php? Module = article & amp; Action = List introduce the following file
Index. php
Config. php
Modules/article/index. php
Modules/article/list. php

Index. php content is as follows:

Code:
Define ("show", true); // defines the entry constant
Require_once ("config. php"); // call the configuration file
$ Module = $ _ Get ["module"]; // call a module
If (empty ($ _ Get ["module"]) $ module = "public"; // Default Value
If (! Preg_match ("/^ [A-Z _] + $/I", $ module) Die ("parameter error! "); // Make the module name parameter only consist of letters and _ characters to prevent injection.
$ Path_module = path_module. $ module. "/"; // module path
Is_file ($ path_module. "index. php") or die (file_null); // stop if the module does not exist.
Require_once ($ path_module. "index. php"); // call the module
......

The content of config. php is as follows:

Code:
Defined ("show") or die (header ("HTTP/1.1 403 not forbidden"); // check whether there is an entry constant
Define ("db_host", "127.0.0.1"); // database address
Define ("db_user", "qh663"); // database username
...... // Other database configurations and global environment settings, such as defining the above constant (path_module)

Modules/article/index. php // module entry, which accepts the operation
Defined ("show") or die (header ("HTTP/1.1 403 not forbidden"); // check whether there is an entry constant
$ Action = $ _ post ["action"]; accept action
If (! Preg_match ("/^ [A-Z _] + $/I", $ action) Die ("parameter error! "); // Make the module name parameter only consist of letters and _ characters to prevent injection.
...... // Handle loading actions and the like here

Modules/article/list. php // execute the corresponding action, which can contain any required code implementation
Defined ("show") or die (header ("HTTP/1.1 403 not forbidden"); // check whether there is an entry constant
One module with only one parameter. One action is also a parameter. Check it out. Is it nice?
The program is independent and integrated. Only the MOD under the modules directory can be operated. The program has only one entry, which is very secure!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.