Introduction to thinkPHP5.0 framework development specifications and thinkphp5.0 framework

Source: Internet
Author: User

Introduction to thinkPHP5.0 framework development specifications and thinkphp5.0 framework

This article describes the thinkPHP5.0 framework development specifications. We will share this with you for your reference. The details are as follows:

Naming rules

ThinkPHP5 followPSR-2Naming rules andPSR-4Automatically load specifications, and pay attention to the following specifications:

Directories and files

The directory is not strictly regulated, and the hump and lower case + underline modes are supported;
Class Libraries and function files are suffixed with. php;
The file names of classes are defined by namespaces, and the paths of the namespaces are the same as those of the class library files;
The class name and class file name must be consistent, and the camper method is used for naming (uppercase letters );

Name functions, classes, and Properties

Class naming is based on the hump method, and the first letter is capitalized. For example:User,UserTypeBy default, no suffix is required, suchUserControllerName it directlyUser;
The function name must start with lowercase letters or underscores (_). For exampleget_client_ip;
The method name uses the camper method, and the first letter is lowercase, for examplegetUserName;
The attribute name uses the camper method and the first letter is lowercase. For example:tableName,instance;
A function or method with the double underscore "_" as the magic method, for example__callAnd__autoload;

Constants and configurations

Constants are named with uppercase letters and underscores, for exampleAPP_PATHAndTHINK_PATH;
The configuration parameters are named with lowercase letters and underscores, for exampleurl_route_onAndurl_convert;

Data Tables and fields

Data Tables and fields are named with lowercase underscores (_). Note that the field name must not start with an underscore. For examplethink_userTable anduser_nameDescription: it is not recommended that you name the data table fields using the hump and Chinese characters.

Application library namespace Specification

The root namespace of the application library is the app (you can set the app_namespace configuration parameter change );

For example, app \ index \ controller \ Index and app \ index \ model \ User.

Avoid using PHP Reserved Words(For a list of reserved words, see http://php.net/manual/zh/reserved.keywords.php)As a constant, class name, method name, and namespace. Otherwise, a system error occurs.

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.