Home  >  Article  >  Backend Development  >  TP controller class file source code

TP controller class file source code

零到壹度
零到壹度Original
2018-03-26 17:32:551799browse

This time I bring you the source code of the TP controller class file. What are the precautions for the source code of the TP controller class file? The following is a practical case, let's take a look.

1. Eight methods of source code:

##2 , Controller knowledge:

a, Accessible controller:

b. Accessible operations (i.e. methods)


(The index operation can be accessed, but the demo operation is private and cannot Access, protected cannot be accessed and must be public)

c. Namespace:

Root namespace: app(application), think(thinkPHP /library), traits (thinkPHP/library)


Controller class name = root namespace + sub namespace (optional) + class name


Controller class Suffix: tp3.3 needs to add a suffix after the controller, in the form: DemoController. The concept of namespace is applied in tp5, so there is no need to add the controller class suffix

Adding the controller class suffix can prevent the controller Class names conflict with keywords

For example, if you want to create a public public controller class without adding it, an error will be reported:

Find the configurator suffix option in the conventional configuration file Defined in the custom configuration file:

Access the method within the

controller and you can also add a controller (function and add to the controller class The same as the controller, to prevent conflicts with system keywords):

Define the List method, because list is a keyword directly defined and an error will be reported:

The suffix of the conventional file operation method is empty by default:


is defined in the custom configuration file



d. Controller naming convention:

Camel case: capitalize the first letter


##Access: (Change uppercase to lowercase and add underline -)

This kind of access requires opening the url configuration item: (the custom file is defined in the custom configuration file)

The above is the detailed content of TP controller class file source code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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