Standard and Convention

Directory Structure

Application Root
|
|----- <application controller folder name>
|       |----- <controller file name>
|
|----- cfg (Configuration and Global Parameters Definition)
|       |----- cfg.inc.php (Defines global parameters)
|
|----- lib (All common includes and classes)
|       |----- model.cls.php (Model Class)
|       |----- view.cls.php (View Class)
|
|----- gui
|       |----- flash (Adobe Flash files)
|       |----- svg (SVG files)
|       |----- img (image files and photos)
|       |----- files (binary files)
|       |----- source (Original images and photos)
|       |----- html (XHTML/XML files)
|       |----- js (Javascripts)
|       |----- style (CSS files)
|
|----- ext (external 3rd party applications)

Coding Standard

PHP

PHP coding should adhere to PHP-Pear coding standard, http://pear.php.net/manual/en/standards.php, and the effort has been to stick to as many common points as possible.

  1. Keep one class one file decorum so that we can use php-doc for technical documentation. More information about PHPDoc can be found here: http://www.phpdoc.de/
  2. Always use <?php ?> to delimit PHP code, not the <? ?> shorthand.
  3. Use an indent of 4 spaces, with no tabs.
  4. If the line is long (i.e., more than 80 characters, the line must be split.
  5. Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls. You are strongly encouraged to always use curly braces even in situations where they are technically optional.
  6. Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon. There should be one space on either side of an equal sign used to assign the return value of a function to a variable.
  7. Function declarations follow the "one true brace" convention. Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate.
  8. Inline documentation for classes should follow the PHPDoc convention, similar to Javadoc.
  9. Non-documentation comments are strongly encouraged. A general rule of thumb is that if you look at a section of code and think "Wow, I don't want to try and describe that", you need to comment it before you forget how it works.
  10. C style comments (/* */) and standard C++ comments (//) are both fine. No Perl/shell style comments (#) should be used. Comments may be added at the start of the program file, before starting functions, or classes or variables, block of code.
  11. Use "example.com", "example.org" and "example.net" for all example URLs and email addresses, per RFC 2606.
  12. Identifier names should be explanatory, and should be in word-case. Also the first letter of the variable or parameter or IDs must tell the nature thereof. Examples (please note carefully) are:
    1. Class: ClassName
    2. Object: oObjectName
    3. Function Name: functionName()
    4. Private Method: _MethodName()
    5. Constants: CONSTANTNAME
    6. String Variable: sVariableName
    7. Array Variable: aVariableName
    8. Integer Variable: iVariableName
    9. Float Variable: fVariableName
    10. Boolean Variable: bVariableName

HTML/XHTML/CSS

  1. Style-sheet must be used for all properties of the HTML elements.
  2. HTML code must be XHTML1.0 strict: http://validator.w3.org/
  3. CSS code must comply with CSS2 standard: http://jigsaw.w3.org/css-validator/
  4. C style comments (/* */) and standard C++ comments (//) are both fine.
  5. ID or NAME attributes should be explanatory, and should be in word-case. Examples (please note carefully) are:
    1. a. CSS Style Class: ClassName
    2. HTML ID Attribute: attributeName
    3. Form ID: formId
    4. Text Box Name/ID: txtFieldName
    5. Text Area Name/ID: taFieldName
    6. Drop Menu Name/ID: dmFieldName
    7. Radio Button Name/ID: rbFieldName
    8. Checkbox Name/ID: chkFieldName
    9. Button Name/ID: btnFieldName
    10. Hidden Field Name: hidFieldName

JavaScript

  1. C style comments (/* */) and standard C++ comments (//) are both fine.
  2. Identifier names should be explanatory, and should be in word-case. Also the first letter of the variable or parameter or IDs must tell the nature thereof. Examples (please note carefully) are:
    1. Object: oObjectName
    2. Method Name: functionName()
    3. String Variable: sVariableName
    4. Array Variable: aVariableName
    5. Integer Variable: iVariableName
    6. Float Variable: fVariableName
    7. Boolean Variable: bVariableName
Get Download Files Review Project Dashboard Know Plan And Wishlist