Home > Article > PHP Framework > 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.
2. Add a getname method in the controller of MyClass.
3. Output a statement in the getname method, and display the statement when the subclass calls the method.
4. Create a new controller named Classson
5. Add the name of the controller you want to inherit after the inherited keyword, MyClassControll.
#6. Add a statement to call the method in the parent class in the default index method.
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.
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!