Design PHP include and require in the two functions, can be in the design of the site to improve the construction efficiency and maintenance of the site, now detailed explained as follows:
The
include function is different from the preprocessing command with the same name in C, which is a given file name (such as include ("test.php")), and PHP applies the file to the include location and tries to interpret the file, which differs from the function in that The code is parsed only when the include statement is executed, so it is common in the design to include the invocation in the IF statement, while the Require H number always contains the specified file, even if it is in a place that is not executed in the IF statement. You can see this in the discussion of the PHP mailing list: Require is faster than include, because PHP can insert the specified file into the script in the early stages of reading through the code. So in programming, if you include a file in a control block (e.g. If,switch,while,for), use include, and the REQUIRC function is used in other cases.
Why should we use include and require in PHP programs? First of all, because it makes the code more readable, the second is that it can be divided into modules, which makes it possible to design in the Web site as long as you write the script to be reused, it can be in the entire site construction and later project reuse, and do not need you to repeat the work, greatly improve the efficiency. Many web sites must rely on repetitive elements, such as consistent navigation bars, which can be user-friendly, but are a big problem for building and maintaining site D. Each page has a code block that must be duplicated. Make it into a module and include or rquire it in every page you need, and only modify it once you need to modify it, that is, just modify the Include script module. So in the construction of a website, should analyze the site that part is duplicate? Then write the duplicate code as a module. The following is a way to partition a site module:
0, Information screen 1, database and file actions 2, H number 3, layout 4, navigation bar.
detailed measures are described below:
The core of the site is the information page it contains, and everything else is dotted. The on-screen display can be HTML or PHP code that extracts and formats data from a database or file, which can continue to be divided into parts based on their number, which is more maintainable than other methods. The first screen's modules correspond to the pages that are accessible on the site. Depending on where the page appears on the site, you can have the appropriate navigation and layout. This Information screen module becomes the key to selecting the remaining modules. such as the website of the press release system.
The
layout module controls where the 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 edge navigation, and possibly also in each page footer has copyright and a file-based navigation bar. Layout put all of these in the full launch. There are two ways to transform a layout module. First of all. You can display the elements where the transformation is placed and select those things. Index pages typically have different navigation elements than level two pages. Similarly the third Polar page may only return links to previous pages.
The
navigation module can be simply listed as an HTML file with links to level three pages. Usually you can indicate a link to the current area by using a different color to indicate the area of the site where the user is currently located. The navigation can be a list of links located on the left side of the page. Each button is an image. They will change as the mouse passes. You can create a module that determines the area based on the screen module that you select. In contrast, it is easy to use an if statement to display a transformation version of a link to the current region.
when building a site, it is very likely that a recurring code snippet will be encountered. function modules can be used to put these functions up.
good to include and require introduction to here, I believe that everyone in the construction of the site will help. In the next database operation of the encapsulation on the application of include and require, hoping to help a large understanding and play a role in the.
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