thinkphp directory structure and naming conventions

Source: Internet
Author: User

Directory structure:


Naming rules:

The following naming conventions should be followed as far as possible during development with thinkphp:
  • Class files are suffixed with. class.php (this refers to the class library file used internally by thinkphp, which does not represent an externally loaded class library file), is named with the Hump method, and capitalized, such as DbMysql.class.php;
  • Ensure that file naming and invocation are case-sensitive, because the case sensitivity is on top of Unix-like systems (while thinkphp is checked for capitalization even on Windows platforms under debug mode);
  • The class name and file name are the same (including the same capitalization), for example, the file name of the Useraction class is UserAction.class.php, and the Infomodel class name is InfoModel.class.php, and the class name of different class library has certain specification;
  • Other class library files, such as functions, configuration files, and so on, are usually suffixed with. PHP (third party not required);
  • The naming of functions uses lowercase letters and underscores, such as GET_CLIENT_IP;
  • Methods are named using the Hump method, and the first letter lowercase or use underscore "_", such as getusername,_parsetype, usually the method that begins with an underscore belongs to the private method;
  • Properties are named using the Hump method, and the first letter lowercase or use underscore "_", such as TableName, _instance, usually the underscore property belongs to the private property;
  • A function or method that begins with a double underscore "__" as a magical method, such as __call and __autoload;
  • Constants are named with uppercase letters and underscores, such as Has_one and Many_to_many;
  • Configuration parameters are named with uppercase letters and underscores, such as html_cache_on;
  • Language variables are named in uppercase letters and underscores, such as My_lang, where a language variable that starts with an underscore is usually used for system language variables, such as _class_not_exist_;
  • There is no mandatory specification for the naming of variables, which can be carried out according to the team specification;
  • The thinkphp template file is suffixed with. html By default (can be modified by configuration);
  • Data tables and fields are named in lowercase and underlined, and note that field names do not start with an underscore, such as the Think_user table and the User_name field, and data table fields like _username may be filtered.
2exception: In thinkphp, there is a special case of a function name, which is a single-letter capitalization function, which is usually a shortcut to some operations, or a special function. For example, ADSL methods and so on, they have a special meaning, there will be some understanding.

Another point is very critical, thinkphp by default all use UTF-8 encoding, so please ensure that your program files are stored in UTF-8 encoding format, and remove the BOM header (there are many ways to remove BOM header information, different editors have a setup method, Tools can also be used for unified detection and processing), otherwise it may lead to many unexpected problems.




thinkphp directory structure and naming conventions

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.