A simple PHP website structure

Source: Internet
Author: User
Tags html header php website
A simple PHP website structure and a simple PHP website structure

Since I have studied website development of asp.net mvc before, when I am new to a new language, I will naturally or unnaturally refer to this experience and then make a website. If you are new to php and write your website in the original way, you can refer to the following method, it is also a possible PHP website structure formed by reference and exploration:

A php website structure

The website name is the project folder, which contains folders such as css, js, images, Des, templates, and up. the functions are as follows:

Directory and function list

Css

It is specially used to store CSS files. Generally, each region is independent of a cssfile, such as user (user.css, product (product.css) and so on.

Images

Used to store images required by websites, such as website logos, background images, and add, query, and modify icons.

Includes

Stores the business logic code. Each module is independent of one file, such as the user (users. php), product (products. php). each file is a collection of various business logic processing methods, such as adding and deleting.

Stores js code in a centralized manner, such as pre-submission verification and improving user experience. Each module is a self-contained file, such as user. js)

Templates

This is a module. if each webpage requires an html header and an html tail, it can be written as a header. php, footer. php, and then include the header and tail (include or require) on each page once to unify the website style

Up Stores the images uploaded by users. First, the images are divided into multiple files by category and then by time, for example,/up/user/2012/2/12/xxxx.jpg.

There are also many independent php files under the root directory, which are the php files presented to users, such as user registration (register. php), login (login. php), home page (index. php files.

Next, we will describe in detail how to implement the functions in each folder:

(1) css folder

This folder is mainly used to combine all css files of a module and define multiple references in one place. in this way, you only need to modify one folder to facilitate modification and maintenance.

As shown in the preceding figure, commom.css is a common Css attribute, such as the link color, the input element goes to the border, and the website text size is uniformly specified, as well as common clearfix or transparent processing code, generally, it will be placed in the header of the website template (/templates/header.php?home.css is used on the first page. then, jquery-ui-1.8.19.custom.css is the standard interface file of jquery.

(2) images folder

It mainly stores some Image resources used by websites, such as logos of different website specifications, background images, add, delete, query, and modify icons, and load icons.

(3) events folder

It mainly stores business logic processing files in a centralized manner. Each module is independent of one file. these files must be included (include or require) during use ):

Where,

A) _ logOn. php is the logOn status bar and has some shortcut menus. it can be regarded as a logOn dashboard:

B) baseConfigus. php is the database configuration information, which is a constant. it is a unified code for easy access to the database and is not easy to make mistakes:

C) commom. php is a common method, such as verifying logon, administrator, uploading files, and displaying pages.

D) users. php is used to process user-related business logic, such as modifying user information and logging in.

(4) js folder

The function structure is similar to the Des folder.

(5) templates folder

The template is used to store website templates. The overall style of the website is as follows:

Header. php defines the header of a webpage. Each basic page must start with (include/templates/header. php ):

Footer. php defines the end of a webpage, and the end of each basic page also needs to include it:

It can include the function back to the top, to the bottom, or add the website traffic statistics code, such as 51la

Header_admin.php and footer_admin.php are templates used on the background page. The principle is similar.

(6) up folder

This folder stores various images uploaded by users, such as user portraits and product portraits. each of them is a folder:

In the user folder, save by year, month, or day.

(7) php files under the root directory

These files are generally directly oriented to users, that is, they are presented to users. Although the business logic is mainly saved in the collections folder, some database access code is still needed on the page. These files must contain website templates in a unified style:

The following uses login. php as an example:

A) header

B) tail

C) Intermediate

Note that the user interface is mainly written in the html language and requires some components:

Css or js reference, form, validation onsubmit = "return validateLogin ();", and keep the information previously entered by the user when a logon error occurs. if ($ _ SERVER ['request _ method'] = 'post') {print $ _ POST ['name'];} and so on

D) Processing of login submission (post mode). the same page is used for processing.

That is, when submitting, the page still jumps to the current page. you only need to determine the submission method (whether it is get or post) and then perform different processing:

If you have logged on to the Get method, the system automatically jumps to the homepage. if you use the Post method, the system performs logon verification. if the verification succeeds, the system jumps to the homepage. if the verification fails, the system stops on the current page.

(8) some processing skills:

A) use the String. Format method of C # for reference (stored in/javasdes/commom. php ):

It is easy to use, for example, when printing data read from the database:

B) because of the method of access in Step a above, the quotation marks (single quotation marks and double quotation marks) are sometimes difficult to escape or escape, that is, errors, jquery may be used flexibly to bind events (rather than html element events), as shown in the confirmation prompt before deletion:

This article is original from bluesky and has independent property rights. if it is reproduced, please indicate the source.

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.