ThinkPHP naming rules

Source: Internet
Author: User

There are a lot of similarities with java. I think it's good to design tp in java!

The framework must have its own specifications, and ThinkPHP is also used. The following naming rules should be followed if ThinkPHP is used:

1. all class files are. class. php is a suffix (this refers to the class library file used internally by ThinkPHP, which does not represent the class library file loaded externally). It is named by the hump method and capitalized, such as DbMysql. class. php.

2. Functions, configuration files, and other class library files are generally suffixed with. php (not required for third-party Introduction ).

3. make sure that the file name is the same as the call case, because it is case sensitive on Unix-like systems (while ThinkPHP is in the debugging mode, even on Windows platforms, the Case sensitivity is strictly checked ).
4. The class name and file name are the same (including the case-insensitive). For example, the file name of the UserAction class is UserAction. class. php, and the file name of the InfoModel class is InfoModel. class. php,
5. Use lowercase letters and underscores to name a function, for example, get_client_ip.
6. The Action controller class is suffixed with Action, such as UserAction and InfoAction.

The Model class is suffixed with Model, such as UserModel and InfoModel.
7. The method name uses the camper method, and the first letter is lowercase, for example, getUserName
The attribute name uses the camper method and the first letter is lowercase, for example, tableName.
8. Use a function or method with the double underline "_" as a magic method, such as _ call and _ autoload.
9. constants are named with uppercase letters and underscores, such as HAS_ONE and many_to_prop.
Name the configuration parameter with uppercase letters and underscores (_), for example, HTML_CACHE_ON.
Language variables are named with uppercase letters and underscores (_). For example, MY_LANG. Language variables with the following dashes are usually used for system language variables, such as _ CLASS_NOT_EXIST _.
10. Data Tables and fields are named using lowercase underscores, such as think_user and user_name ,~~~~ (>_< )~~~~

Special case:
In ThinkPHP, there is a special name for a function, that is, a single-letter upper-case function, which is usually a quick definition of some operations or has a special role. For example, the ADSL method has a special meaning and will be understood later.
Also, ThinkPHP uses UTF-8 encoding by default, so please make sure that your program files are saved in UTF-8 encoding format, and remove the BOM information header (remove BOM header information in many ways, different editors have different settings. You can also use tools to perform unified detection and processing ).

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.