Naming conventions
ThinkPHP5FollowPSR-2Naming conventions andPSR-4Automatically load specifications, and note the following specifications:
Directories and files
- Directory does not enforce the specification, hump and lowercase + underline mode are supported;
- Class Library, function file unification to
.php be suffix;
- The file name of the class is defined in the namespace, and the path to the namespace is the same as the path to the class library file;
- The class name and the class file name are consistent, using the Hump method to name (capitalize);
Functions and classes, property naming
- Class is named with the Hump method, and the first letter is capitalized, for example
User、UserType, you do not need to add a suffix by default, such asUserControllerShould be named directly asUser;
- The name of the function uses lowercase letters and underscores (lowercase letters begin) In a way that is, for example
get_client_ip ;
- The name of the method uses the Hump method, and the first letter is lowercase, for example
getUserName ;
- The
- property is named using the Hump method, and the first letter is lowercase, for example
tablename , instance ;
- A function or method preceded by a double underscore "__" as a magical method, for example
__call __autoload ;
Constants and configurations
- The
- constants are named with uppercase letters and underscores, such as
app_path and think_path ;
- Configuration parameters are named with lowercase letters and underscores, for example,
url_route_on and url_convert ;
Data tables and fields
- Data tables and fields are named in lowercase and underlined, and note that field names do not start with an underscore, such as
think_user tables and user_name fields, and it is not recommended to use hump and Chinese as the table field name.
Application Class Library namespace specification
The root namespace of the Application class library is unified as an app (you can setapp_namespaceConfiguration parameter change);
For example:app\index\controller\IndexAndapp\index\model\User。
Avoid using PHP reserved words (see http://php.net/manual/zh/reserved.keywords.php ) as constants, class names and method names, and namespace naming, which can cause system errors.
thinkphp5.0 Development Code