TP controller class file source code

零到壹度
Release: 2023-03-22 10:58:01
Original
1806 people have browsed it

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!