/ **
* Copyright (C) 2004 Beijing West Line Media Technology Co., Ltd.
* Author: Liu Zhenfei liuzf@pku.org.cn; Wang Chunsheng wwccss@263.net
* Produced: Beijing West Line Media Technology Co., Ltd. Technology Http://www.okooo.com
*
* This program is free software, you can follow the GNU General Public License Terms published in the Free Software Foundation
* Remove this procedure. Or use any update with the second edition of the license, or (according to your choice)
* Version.
*
* The purpose of publishing this program is to hope it is useful, but there is no guarantee. Even if it is not suitable for a specific purpose
* Guarantee. For more detailed information, please refer to the GNU universal public license.
*
* You should have received a copy of a GNU universal public license with a program. If not, write a letter to:
* The Free Software Foundation, INC.,
* 675 Mass AVE,
* Cambridge, Mao2139, USA
* Should also add how to keep in touch with you.
*
* Reference documentation: http://www.w3cn.org/Article/Step/2004/26.html, thank the original author.
*
* Welcome to "West Line Media Free Software Park": http://www.okooo.com/opensource/, we will release useful free software here.
* /
First, the file structure:
The entire website directory structure is as follows: (color example: first-level catalog secondary directory level three directory)
/ Root directory (such as: / home / www /, may vary.)
| --- Documents (Store developed document file)
| --- INCLUDE (stored in file)
| --- Class definition file, each class separately a file to define.)
| --- ClassFile1
| --- ClassFile2
| --- ..........
| --- Config.inc.php Storage System Parameter Settings Information.
| --- functions.inc.php public library file.
| ---- OtherFunction.inc.php Library files for other specific applications. Name according to the actual situation.
| --- setup.inc.php parameter variable initialization file. Other programs can directly contain this file.
| --- HTML
| --- Images (Store website image files, and establish the corresponding subdirectory according to the name of the column.)
| --- CHANNELNAME1 (Picture File) Store ChannelName1 Column)
| --- ChannelName2
| --- CSS (store website style sheet file)
| --- Include (files needed in the web page, such as JS teaching, etc.)
| --- ChannelName1 (stored the program file of the ChannelName1 column.)
| ---- ChannelName2
| --- ..........
| --- Admin (Managers for the entire site. This directory needs to be protected by various methods.)
| - -cache (Smarty Template generated cache file, directory permissions need to be writable.)
| --- Compile (SMARTY Template generated compilation, directory permissions need to be writable.)
| --- Smarty (Store smarty file)
| --- PEAR (stores PEAR files, optional. Because the system itself has pear ..)
| --- Templats (SMARTY template file, the directory structure corresponds to the HTML directory structure.)
| --- Images (Store website image files, and establish a corresponding subdirectory according to the name of the column.) | --- ChannelName1 (Picture File) of the ChannelName1 column)
| --- ChannelName2
| --- CSS (store website style sheet file)
| --- Include (files needed in the web page, such as JS teaching, etc.)
| --- ChannelName1 (stored the program file of the ChannelName1 column.)
| ---- ChannelName2
| --- ..........
Second, catalog, file naming conventions:
Directory, file naming is in English, the length is generally not more than 20 characters, and the name of the case is used. In addition to special circumstances, Chinese pinyin is used. For example: images, getusername.php changepassword.php
Third, the components of the PHP script file:
Each document is arranged in the following order: Document Description section, contains file parts, variable declarations, initializes, custom functions, and specific statements.
3.1 Document Description Part
At the beginning of each document, you want to include the number of this document, a brief description, and the author and final modification. Note When using phpDocument's annotation.
/ **
* Okoo.com Homepage (Simply Note)
*
* This file provides a shared function file applied to the website (detailed instructions).
* @file $ source $
* @package index (which module belonging to, can be divided according to the functionality of the program.)
* @Author Wang Chunsheng
* @version $ ID $
* /
?>
If the page is a pure web page, you can explain in the following form: Note that it starts with HTML annotation statements.
/ **
* Homepage (simple note)
*
* This file provides a shared function file applied to the website (detailed instructions).
* @file $ source $ * @Package INDEX
* @Author Wang Chunsheng
* @version $ ID $
* /
->
The $ ID $ ID $ will automatically replace the file basic information after CVS, which contains CVS information such as file name, date, and modifier.
3.2 Contains the file part:
The beginning of each document contains the included files used in this document.
For example: include ("setup.inc.php");
Note: If you use session, you need to put the session_start () function to the first sentence of the document.
3.3 Variable Description Part:
If there is a variable that requires a special statement, it is given here. It can be explained by the way of comment statements. such as:
// Username The user name of the user is currently logging in.
3.4 Custom Function Part:
If the current PHP script needs to define a function, this declare. Any of two functions for more than two documents are placed in the public library file, ie /include/functions.inc.php files.
Custom functions need to include the following sections: Function Description, Function Variable Description, Return Value Description.
Example:
/ **
* Database connection function (briefly)
*
* Linked to the database through this function and returns a trusted link identifier. (Detailed explanation)
* @Author Wang Chunsheng
* @version 1.0 * @global string database server (global variable declaration, no need to specify variables, order corresponding)
* @Global String Database Username
* @global string database password
* @global string database to use
* @Param String $ SQL connection successfully executed query statement, the default is empty. (Variable statement)
* @Return Array Returns the database connection information. (Return value description)
* /
Function Dbconnect ($ SQL = "")
{
Global $ DBHOST, $ DBUSER, $ DBUSERPWD, $ DBDATABASE
$ Connifo = array (); // Store connection information
$ Linkid = mysql_connect ($ DBHOST, $ DBUSER, $ dbuserpwd); / / Connect to the database, return connection ID
MySQL_SELECT_DB ($ dbdatabase); // Select the database
$ Results = mysql_query ($ SQL, $ LINKID); // Return Query Result ID
$ Connifo ["linkid" = $ linkID; // Save two IDs to array $ connInfo
$ Connifo ["resultid" = $ results;
RETURN $ connInfo; // Return Array $ ConnInfo
}
?>
3.5 File ends:
The following notes must be written in all text files (PHP, HTM, etc.):
PHP:
/ **
* $ Log $
* /
?>
HTM:
/ **
* $ Log $
* /
->
This comment will automatically replace the file modification record after CVS Checkout.
Fourth, program annotation conventions:
The documentation and function describes the form of phpdocument
The module illustrates the form of comments on the sentence. Description of each statement adopts the way to write.
Note to the file declaration and the function of the function Refer to the above format.
Here is the annotation format of class files.
PHP
/ **
* Data Record Points Display Class. (Brief Description of the entire class file)
*
* A class regarding the data paging display, you can select a page through a drop-down list. (Detailed explanation)
* @Package Include (the module name to which you belong)
* @Author Wang Chunsheng
* @version $ ID 2003-12-6 21:30 $
* /
Class Page
{
/ **
* Total number of records. (Statement to class properties.)
* @var int
* /
Var $ RectAl;
/ **
* The number of records per page is displayed.
* @var int
* /
Var $ RECPERPAGE;
/ **
* Total the total number of records of a certain condition query. (Instructions for the class method, the same as the description of the function)
*
* @Global Object $ dB database link information.
* /
Function GetRectotal ()
{
GLOBAL $ mysql;
..........
} ``
V. PHP statement writing format agreement:
IF ($ usrname = = "xxx" and $ password = = "xxx") {
Echo "Hello";
}
Else
{
echo "Oh";
}
Braces are divided into two columns, and the reason is convenient to define the range of braces.
The indentation uses four spaces without using the Tab key to indent.
The function name is spaced between the parameters. For example: $ linkid = mysql_connect ($ username, $ host)
6. Named mode of PHP variables follows the following principles:
(1) Size mixing: distinguishes on the form of uppercase mixing. For example: username
(2) If there is a word abbreviation, a capital form is used. Such as: SQL. At the same time, the word should be avoided, such as IMGFILE, can not directly determine the segmentation of the word, should be written into IMGFILE. The name of the class is similar to the variable naming, which is also used in cases in cases. Class properties adopt _ start, such as $ object -> _ var1
7. PHP function naming conventions:
The form of verb additive, verb lowercase, the name of the next name is spaced apart. If you need, you can increase your lowermill, and this time the verb is on the point. such as:
No prefix: getUsername
Prefix: sysgetusername
Eight, database change field naming conventions:
(1) Database, table, field naming is the same as the PHP variable, using case-write mixing, such as Database: Okooo
Table: UserList
Field: Username, Userpassword, Birthdate ...
(2) The keywords in the SQL query statement use capitalization. For example: Select * from userlist where ......
(3) Module Description Document If there is a database definition, follow the format:
Module name (such as: user table) table name (such as UserList)
Description of the table: System user table
Serial number
Field name
Field description
Field type, size
Is empty
Defaults
Key name
index
1
Scholarid
Scholar number
Smallint unsigned
NOT
Self-increasing
Y
Y
2
ScholarName
Scholar's name
VARCHAR (20)
NOT
N
Y
3
Sortid
Order
Tinyint unsigned
NOT
1
4
Scholarintro
Scholar profile
TEXT
NOT
N
Y
5
Images
Scholar picture
VARCHAR (79)
6
Adduaser
Adder
VARCHAR (30)
NOT
Seduce
Updatedate
Last update time
Datetime
0
Note: Description of some fields. Or your own design ideas.
If the database has been changed later, the document should be changed, keep synchronization.
Nine, CVS operational agreement:
(1) Plus $ ID $ and $ CVS TAG before and files, please refer to the Composite of the PHP Script File "section.
(2) When CVS Checkin must write a comment, the content of the comment must be the modification of this version, such as:
Add username check
* Fixed the password BUG
- Remove the ABCDE function
The detailed description is as follows:
1) Changes to the symbols, " " indicates the new function, "*" means the modification function, "-" means the function of the deletion;
2) Each change occupies a row; 3) There is a space before and after the symbol (" ", "-" and "*").
Ten, XHTML code specification
10.1 reference to the style sheet
Style sheets are called by external references, which is not recommended to newly defined in the page.
The form of display in the page element is not recommended to define by HTML code, and all the style sheets are unified.
For example, you want to display a red font, you can define this with an HTML code:
red font font>
But the best way is to define through style sheets.
Red field font>
This will focus on the definition of the website style to a style sheet file, if you modify the site, you can make it quickly. And if it is dispersed into each web file, it is very troublesome to change it.
10.2 indentation, refund
Network code indentation uses two spaces.
Because the page nested tag may be more, it is used to indent the code of the deepest layer to indent too much, so it uses two spaces to indent.
If the code in a row is too long, please go back.
Such as such a line of code
Can be changed
td>
TR>
If multi-line similar code appears, the property is as aligned.
such as
The Type, Name and the Value property are more convenient to read it later.
For a plurality of properties of some mark, the order is as close as possible.
For example, the definition of the Table tag can be defined in the order below.
Must be modified to: |
td> 10.4 Table Single Volume Naming Convention The variable named in the form is named using a PHP, using the case interval. such as: |