Detailed introduction to thinkPHP5.0 framework development specifications

黄舟
Release: 2023-03-07 06:06:01
Original
1966 people have browsed it

This article mainly introduces the thinkPHP5.0 frameworkdevelopment specifications, and briefly analyzes the naming conventions and specifications of various variables, constants, files, directories, class libraries, etc. of thinkPHP5.0 Notes, friends in need can refer to the following

The examples in this article describe the thinkPHP5.0 framework development specifications. Share it with everyone for your reference, the details are as follows:

Naming convention

ThinkPHP5 follows the PSR-2naming convention and PSR-4 Automatically load specifications, and pay attention to the following specifications:

Directories and files

Directories are not mandatory specifications, camel case and lowercase + underline mode Both are supported;
class libraries and function files are all suffixed with .php;
class file names are defined with namespace , and the path of the namespace is consistent with the path of the class library file;
The class name and the class file name should be consistent, and uniformly use camel case naming (the first letter is capitalized);

Functions and classes, AttributesNaming

Classes are named using camel case, and the first letter is capitalized, such as User, UserType. By default, no suffix is ​​required. For example, UserController should be named directly User;
Functions are named using lowercase letters and underscores (starting with a lowercase letter), for example get_client_ip;
Methods are named using camel case, and the first letter is lowercase. For example, getUserName;
attribute naming uses camel case, and the first letter is lowercase, such as tableName, instance;
starts with a double underscore "" functions or methods as magic methods, such as call and autoload;

constants and configuration

constants are in uppercase letters and underscores, such as APP_PATH and THINK_PATH;
Configuration parameters are named with lowercase letters and underscores, such as url_route_on and url_convert;

Data tables and fields

Data tables and fields are named in lowercase and underlined, and be careful not to start the field name with an underscore, for example think_user Table and user_name fields, it is not recommended to use camel case and Chinese as data table field names.

Application class library namespace specification

The root namespace of the application class library is unified as app (the app_namespace configuration parameter can be set to change);

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

Please avoid using PHPReserved keywords (See http://php.net/manual/zh/reserved.keywords for the list of reserved words .php)as constants, class names, method names, and namespace naming, otherwise system errors will occur.

The above is the detailed content of Detailed introduction to thinkPHP5.0 framework development specifications. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template