PHP——Modular design_PHP tutorial

WBOY
Release: 2016-07-13 17:22:31
Original
915 people have browsed it

The two functions in include and require in PHP can improve website construction efficiency and maintenance in website design. They are explained in detail as follows:
The include function is different from the preprocessing command of the same name in C. It is Once a file name is given (such as: include("test.php")), PHP will call the file to the include location and try to interpret the file. The difference between it and the function is that the code only executes the include statement. is parsed, so the design usually includes the call in the if statement to take advantage of this; the require H number always includes the specified file, even if it is located in a place that is not executed in the if statement. You can see this problem in the discussion on the PHP mailing list: require is faster than include because PHP can insert the specified file into the script in the early stage of reading the code. Therefore, in programming, if a file is included in a control block (such as if, switch, while, for), include is used, and in other cases, the requirec function is used.
Why should we use include and require in PHP programs? First of all, because it makes the code more readable, and secondly because it can divide the site into modules, which allows you to build and build the entire site as long as you write the scripts to be reused in the design of the site. It can be reused in future projects without the need for you to repeat work, which greatly improves work efficiency. Many web sites must rely on some repetitive elements, such as a consistent navigation bar, which can facilitate user operations, but creates great problems in building and maintaining the site. Each page has blocks of code taped to it that must be repeated. Make it into a module and include or rquire it in every required page. When modification is needed, you only need to modify it once, that is, only modify the included script module. So when building a website, you should analyze which parts of the site are duplicated? Then write the repeated code into modules. The following is a way to divide the site modules:
0. Information screen 1. Database and file actions 2. H number 3. Layout 4. Navigation bar.
The details are as follows:
The core of the website is the information page it contains, and other things are embellishments. What is displayed on the screen can be HTML or PHP code, extracting and formatting data from a database or file. These screens can be further divided into sections based on their number, which is easier to maintain than other methods. The modules on the first screen all correspond to accessible pages on the site. Depending on where the page appears on the site, there can be corresponding navigation and layout. In this way, the information screen module becomes the key to selecting other modules. Such as the news release system of the website.


The layout module controls where content appears on the page. The main part of the content is the output of the screen module. Of course, there will also be other content such as top navigation and side navigation, and there may also be copyright and a file-based navigation bar in the footer of each page. The layout pushes all of that out. The layout module has two transformation methods. first. You can transform where to place elements and select what to display. Index pages generally have different navigation elements than secondary pages. Likewise third pole pages may only have links back to previous pages.
The navigation module can be simply listed as an HTML file with links to third-level pages. Often you can hint to users about the area of ​​the site they are currently in by using another color to indicate the link to the current area. Navigation can be a list of links located on the left side of the page. Each button is an image. They change as the mouse passes over them. It is possible to create a module that determines the area based on the selected screen module. Relatively speaking, it is easier to use an if statement to display a transformed version of the current zone link.
When building a site, it is very likely that you will encounter repeated code snippets. Function modules can be used to put these functions in place.
That’s it for the introduction to include and require. I believe it will be helpful to everyone in the construction of the website. In the encapsulation of database operations in the next article, include and require are used. I hope it can help everyone understand and serve as a starting point.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532319.htmlTechArticleThe two functions include and require in PHP can improve the efficiency and efficiency of website construction in website design. Maintenance is explained in detail as follows: The preprocessing command with the same name as the include function in C is...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template