TP development specifications

Source: Internet
Author: User
Naming rules

The following naming rules should be observed during thinkphp development:

  • 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, for exampleDbMysql.class.php;
  • The namespace address of the class is the same as the path address, for exampleHome\Controller\UserControllerThe path of the class should beApplication/Home/Controller/UserController.class.php;
  • 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 );
  • The class name and file name are the same (including the case-insensitive), for exampleUserControllerClass file name isUserController.class.phpThe file name of the infomodel class isInfoModel.class.phpAnd the class names of different class libraries have certain specifications;
  • Functions, configuration files, and other class library files.phpSuffix (not required by a third party );
  • The name of a function uses lowercase letters and underscores, for exampleget_client_ip;
  • The method name uses the camper method, and the first letter is lowercase or the underline "_", for examplegetUserName,_parseTypeGenerally, the method starting with an underscore is a private method;
  • The attribute name uses the camper method, and the first letter is lowercase or the underline "_", for exampletableName,_instanceGenerally, attributes starting with an underscore are private attributes;
  • A function or method with the double underscore "_" as the magic method, for example__callAnd__autoload;
  • Constants are named with uppercase letters and underscores, for exampleHAS_ONEAndMANY_TO_MANY;
  • The configuration parameters are named with uppercase letters and underscores, for exampleHTML_CACHE_ON;
  • Language variables are named with uppercase letters and underscores, for exampleMY_LANGThe following underlined language variables are usually used for system language variables, such_CLASS_NOT_EXIST_;
  • There is no mandatory specification for variable naming, which can be implemented according to team specifications;
  • The default thinkphp template file is.htmlSuffix (can be modified through configuration );
  • Data Tables and fields are named with lowercase underscores (_). Note that the field name must not start with an underscore. For examplethink_userTable anduser_nameThe field is written correctly, similar_usernameSuch data table fields may be filtered out.

Special case: In thinkphp, there is a special function naming case, that is, a single-letter upper-case function, which is usually a quick definition of some operations, or has a special role. For example, Methods A, D, S, and l have special meanings and will be understood later.

Because thinkphp uses UTF-8 encoding by default, make sure that your program files are saved in UTF-8 encoding format and remove the BOM header (there are many ways to remove the BOM header information, different editors have different setting methods, and you can also use tools for unified detection and processing). Otherwise, many unexpected problems may occur.

Development Suggestions

During thinkphp development, we provide the following suggestions to make your development easier:

  • Follow the naming and directory specifications of the framework;
  • Enable the debugging mode as much as possible during the development process to detect problems as soon as possible;
  • Take a look at the log files to find hidden problems;
  • Develop a good habit of getting input variables using the I function;
  • When the update or environment changes, the first problem is to clear the runtime directory;

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.