This time I will bring you a detailed explanation of the inheritance base and custom class cases of the ThinkPHP5.0 framework controller. What are the precautions for the ThinkPHP5.0 framework controller inheritance base and custom class? The following are Let’s take a look at practical cases. z
Inherit the system controller base class:
<?php namespace app\index\controller; use think\Controller; class Index extends Controller { public function hello() { return 'hello,world'; } }
or customize a base controller class Base:
<?php namespace app\index\controller; use think\Controller; class Base extends Controller { }
can be in the Base controller class Define some public methods in it (if you are not familiar with the basic knowledge of classes, please refer to the Classes and Objects section of PHP for very clear explanations, so I won’t go into details here).
Then all controller classes below the application inherit Base:
<?php namespace app\index\controller; use app\index\controller\Base; class Index extends Base { public function hello() { return 'hello,world'; } }
It is recommended to define a unified controller base class for the application to facilitate later expansion.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to implement ADODB transaction processing in PHP
How to use Thinkphp5 uploadify to implement file upload
The above is the detailed content of Detailed explanation of ThinkPHP5.0 framework controller inheritance base and custom class cases. For more information, please follow other related articles on the PHP Chinese website!