The following four locations for storing Web files are required for each project/site:
| /plan | for pre-web development, such as documentation, graphics and HTML mockups |
| /dev | for code development and debugging |
| /stage | for staging area; testing and QA |
| /migrate | a mirror of the staging; for migrating data from an existing site to a new DB |
| / | live; available to end users |
All non-live areas should be password-protected to allow only developers. Clients may have access to the /stage directory.
file_name.php, file_name.htm
Files should be all lowercase, with a three-letter file extension. Words should be separated by an underscore ("_") character. The first word should be the section, followed by a sub-section (if necessary) and finally by the action. For example, a file that creates a new record for Events might be named events_add.php. Use only alpha-numeric characters, period and underscore only.
Because of Windows limitations, HTML files should have a .htm suffix, rather than the Mac and UNIX .html.
Included files should be preceded with "inc_" and have a three-letter extension. If they are PHP files, the extension should be .php. For example: inc_top.php.
TableName, PRE_TableName
MySQL database tables should be InterCapitalized, with the first letter of each word capitalized. If a category is necessary, use a short abbreviation, in all caps, proceeded by an underscore and a description of the table. Be careful to avoid using language keywords as table names. Use alpha-numeric characters only.
Table names should always be singular, describing one record of the table. Two examples are Employee and Company.
FieldName, ID, TableID
MySQL field names should be InterCapitalized, with the first letter of each word capitalized. Be careful to avoid using language keywords as field names. Do not use the name of its table as the field name. Use alpha-numeric characters only.
Primary key fields should be called ID. Foreign key fields should start with the name of the table they relate to, followed by "ID". For example, if the One table is Company and the Many table is Employee, use CompanyID as the foreign key in each record in the Employee table.
Whenever possible, use the field names Name and Description if these fields exist. Then makes it easier to reuse SQL statements.
$MyVariable, $row["DatabaseVariable"]
PHP variable names always start with a dollar sign ("$") and should be InterCapitalized, with the first letter of each word capitalized. Use alpha-numeric characters only.
MySQL variable names follow the same convention, but without the dollar sign ("$").
In general, variable names should be as descriptive as possible, without being unnecessarily long. A variable that is used in very limited scope may have a short name, such as using $i in loops.
ClassName
Wherever used (defining or specifying), CSS class and ID names should be InterCapitalized, with the first letter of each word capitalized. For example, <p class='TopLevel'> and div.ErrorMessage {}.
There should be a section of comments at the top of each page, above all other code or HTML elements (immediately after <?php), with the following information:
This information should be contained in an ASCII box created using the slash ("/") character and any others that will create a visual box. For example:
///////////////// // // Comments... // /////////////////
or
//------------------ // // Comments... // //------------------
or
//=================// // // // Comments... // // // //=================//
etc.
The style of the box is left up to each programmer, but it should be consistent across all of a programmer's files.
When there is a section of code that is related, or can be logically grouped, it should be labeled at the top with either a small comment box or line. The comments should describe the code below it, and start at the left edge of the screen, with no code on the same line. If a small ASCII box is used, it should be similar in style to the large box at the top. The size of the box should also represent the amount or importance of the code it describes. For example, a large, ornate box shouldn't be used with two lines of code.
For example:
// Comment here lines of code...
or
//================ // Comment here... //================ lines of code...
Inline comments describe a single line of code, and are usually placed at the end of the line. For example:
$Variable = "Value"; // Comment goes here
SQL statements are easier to read if they are broken into multiple lines. Each keyword should be in all-caps on its own line, followed by a new line, then a tab for the parameters. Each parameter should be on its own line, indented from the keyword. For example:
SELECT ID, FirstName, LastName FROM TableName WHERE ID > 5
Curly braces should be on separate lines, directly under the statement they go with. Anything contained in the braces should be indented one tab in from the braces on separate lines. For example:
if ($i > 5)
{
echo "\$i is greater than 5";
}
else
{
echo "\$i is less than 5";
}
or
while ($i < 5)
{
echo $i;
$i++;
}
This applies to other similar code, such as defining functions and classes.
There should be one space in the following scenarios:
if ($test) or SomeFunction($Parameter)SomeFunction($A, $B, "test")$i = $a + $b;if ($x < $z) or if ($x < $z && $a < $b)HTML needs to look good for several reasons: debugging, redesigning, and because anyone can see our HTML source.
<!-- Start navigation bar here -->Example:
<table class='Dark'>
<tr>
<td>
Table content
</td>
</tr>
</table>
Formatting Cascading Style Sheets correctly and consistently will make it easier to add, edit, and find things in a style sheet document.
Example:
p.Dark
{
background-color: #030;
color: #999;
}