Home  >  Article  >  PHP Framework  >  How thinkphp controller inherits classes

How thinkphp controller inherits classes

王林
王林Original
2019-09-11 17:52:033889browse

How thinkphp controller inherits classes

A custom public controller will be used in thinkphp. I hope to inherit this controller in other controllers. So how to inherit this class?

1. First create a controller as a custom class that needs to be inherited and name it MyClass.

How thinkphp controller inherits classes

2. Add a getname method in the controller of MyClass.

How thinkphp controller inherits classes

3. Output a statement in the getname method, and display the statement when the subclass calls the method.

How thinkphp controller inherits classes

4. Create a new controller named Classson

How thinkphp controller inherits classes

5. Add the name of the controller you want to inherit after the inherited keyword, MyClassControll.

How thinkphp controller inherits classes

#6. Add a statement to call the method in the parent class in the default index method.

How thinkphp controller inherits classes

7. Run the Classson controller and find that you can call the method in the parent class and output the string in the method in the parent class.

How thinkphp controller inherits classes

The above content is for reference only!

Recommended tutorial: thinkphp tutorial

The above is the detailed content of How thinkphp controller inherits classes. 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
Previous article:thinkphp hook meansNext article:thinkphp hook means