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.