PHP--进行模块化设计_PHP
PHP中的include和require中的两个函数,能在网站的设计中提高网站的建设效率与维护,现详细讲解如下:
include 函数与C中同名的预处理命令是不同的,它是一个给出文件名(如:include("test.php")),PHP就把文件调用于include的位置,并方试图解释该文件,它与函数的差别在于,只有执行include语句时,代码才被解析,因此在设计中通常在if语句中包含调用来得用这一优点;而require H数则总是包含了指定的文件,即使它位于if 语句中不被执行的地方。大家可以在PHP邮件列表的讨论中可以看见到这个问题:即require比include要快,因为PHP可以在通读代码的前期就可将指定文件插入到脚本中。所以在程序设计中若将一个文件包含在一个控制块中(如:if,switch,while,for),则用include,而其它情况就使用requirc 函数。
为什么我们应在PHP程序中使用include 和require呢?首先,首先是因为这样使代码可读性更好,其次是它可将站点分成 模块,这使得可以使在网站的设计中你只要编写了要复用的脚本,便可以在整个站点的建设及以后项目中复用,而不需要你重复工作,极大的提高了工作效率。许多web站点必须依赖一些重复的要素,如始终如一的导航条,它可以方便用户操作,但却给建设和维护站点D来很大问题。每一页都有必须重复的代码块贴在上面。把它做成模块并在每一个需要的页面中include or rquire 它,当需要修改时只需要修改一次即可,即只修改include的脚本模块即可。所以在一个网站的建设中,应该分析站点那部分是重复的?然后把重复的代码写成模块。如下是对站点模块划分的一种方式:
0、信息屏幕 1、数据库和文件动作 2、H数 3、布局 4、导航条。
现详细措述如下:
网站的核心是它所含的信息页面,其它的东西都是点缀。屏幕上显示的可以是HTML,也可以是PHP代码,从数据库或文件中提取并格式化数据,这些屏幕可根据其数量继续划分成各部分,这样比其他方法更有助于维护。第一屏的模块都与站点上可访问的页面相对应。根据页面在站点上出现的位置,可有相应的导航和布局。这样信息屏幕模块就成为选其余模块的关键。如网站的新闻发布系统。
布局模块控制内容出现在页面的地方。内容的主要部分是屏幕模块的输出。当然也还会有其他内容如顶部导航和边部导航等,可能还在每页的页脚有著作权和一个基于文件的导航条。布局把所有这些全推出去。布局模块有两种变换方式。首先。可以在变换在什么地方放置元素以及选择那些东西来显示。索引页面一般与二级页面有不同的导航元素。同样第三极页面可能只有返回以前页面的链接。
导航模块可以简单列为一个关于三级页面链接的HTML文件。通常你可以通过用另一种颜色来标明对当前区域的链接来暗示用户他们现在所在的站点的区域。导航可以是位于页面左边的链接列表。每个按纽都是一个图像。在鼠标通过时它们会有所改变。可以创建一个模块,根据所选择的屏幕模块决定区域。相对来讲,用if语句来显示对当前区域链接的一种变换版本是比较容易的。
在构建站点时,极有可能碰上重复出现的代码段。用函数模块可以用来把这些功能放起。
好了对include和require的介绍就到这里了,相信对大家在网站的建设中会起到帮助。在下一篇数据库操作的封装就应用了include和require,希望能帮助大理解及起到抛砖引玉作用。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Open WeChat, select Settings in Me, select General and then select Storage Space, select Management in Storage Space, select the conversation in which you want to restore files and select the exclamation mark icon. Tutorial Applicable Model: iPhone13 System: iOS15.3 Version: WeChat 8.0.24 Analysis 1 First open WeChat and click the Settings option on the My page. 2 Then find and click General Options on the settings page. 3Then click Storage Space on the general page. 4 Next, click Manage on the storage space page. 5Finally, select the conversation in which you want to recover files and click the exclamation mark icon on the right. Supplement: WeChat files generally expire in a few days. If the file received by WeChat has not been clicked, the WeChat system will clear it after 72 hours. If the WeChat file has been viewed,

In Windows, the Photos app is a convenient way to view and manage photos and videos. Through this application, users can easily access their multimedia files without installing additional software. However, sometimes users may encounter some problems, such as encountering a "This file cannot be opened because the format is not supported" error message when using the Photos app, or file corruption when trying to open photos or videos. This situation can be confusing and inconvenient for users, requiring some investigation and fixes to resolve the issues. Users see the following error when they try to open photos or videos on the Photos app. Sorry, Photos cannot open this file because the format is not currently supported, or the file

Tmp format files are a temporary file format usually generated by a computer system or program during execution. The purpose of these files is to store temporary data to help the program run properly or improve performance. Once the program execution is completed or the computer is restarted, these tmp files are often no longer necessary. Therefore, for Tmp format files, they are essentially deletable. Moreover, deleting these tmp files can free up hard disk space and ensure the normal operation of the computer. However, before deleting Tmp format files, we need to

Quark Netdisk and Baidu Netdisk are currently the most commonly used Netdisk software for storing files. If you want to save the files in Quark Netdisk to Baidu Netdisk, how do you do it? In this issue, the editor has compiled the tutorial steps for transferring files from Quark Network Disk computer to Baidu Network Disk. Let’s take a look at how to operate it. How to save Quark network disk files to Baidu network disk? To transfer files from Quark Network Disk to Baidu Network Disk, you first need to download the required files from Quark Network Disk, then select the target folder in the Baidu Network Disk client and open it. Then, drag and drop the files downloaded from Quark Cloud Disk into the folder opened by the Baidu Cloud Disk client, or use the upload function to add the files to Baidu Cloud Disk. Make sure to check whether the file was successfully transferred in Baidu Cloud Disk after the upload is completed. That's it

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

How to add trusted sites in Google Chrome? Some users cannot browse the web normally because the page prompts that it is not secure when surfing the Internet. At this time, they can add the website as a trusted site, and we can access it normally and surf the Internet smoothly. The editor below will bring you the steps to add a trusted site in Google Chrome. The steps are simple and easy to operate, and even beginners can easily get started. Friends who need it can learn about it together. How to add a trusted site in Google Chrome: 1. Open Google Chrome and click the three dots in the upper right corner. Click [Settings]. Choose privacy settings and security. (As shown in the picture) 2. Click Website Settings at the bottom of the page. (As shown in the picture) 3. Click on the unsafe content at the bottom of the page. (As shown in the picture) 4. Click the Add button to the right of the Allow option. (As shown in the picture) 5. Lose

Recently, many netizens have asked the editor, what is the file hiberfil.sys? Can hiberfil.sys take up a lot of C drive space and be deleted? The editor can tell you that the hiberfil.sys file can be deleted. Let’s take a look at the details below. hiberfil.sys is a hidden file in the Windows system and also a system hibernation file. It is usually stored in the root directory of the C drive, and its size is equivalent to the size of the system's installed memory. This file is used when the computer is hibernated and contains the memory data of the current system so that it can be quickly restored to the previous state during recovery. Since its size is equal to the memory capacity, it may take up a larger amount of hard drive space. hiber

A file path is a string used by the operating system to identify and locate a file or folder. In file paths, there are two common symbols separating paths, namely forward slash (/) and backslash (). These two symbols have different uses and meanings in different operating systems. The forward slash (/) is a commonly used path separator in Unix and Linux systems. On these systems, file paths start from the root directory (/) and are separated by forward slashes between each directory. For example, the path /home/user/Docume
