This time, we bring you ThinkPHP5.0. Framework controller inheritance base and custom class case study, ThinkPHP5.0 framework controller successor base and custom class of attention to what, the following is the actual case, take a look. Z
Inherit the system controller base class:
<?phpnamespace app\index\controller;use Think\controller;class Index extends controller{public function Hello () { return ' Hello,world '; }}
Or customize a base controller class base:
<?phpnamespace app\index\controller;use think\controller;class Base extends controller{}
You can define some public methods in the base controller class (If you are not familiar with the basic knowledge of the class, refer to the PHP classes and Objects section is very clear, do not do in-depth).
Then all of the following controller classes are applied to inherit base:
<?phpnamespace app\index\controller;use App\index\controller\base;class Index extends base{public function Hello () { return ' Hello,world '; }}
It is recommended to uniformly define your own controller base class for the application, which is convenient for later extension.
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
How to implement ADODB transaction processing in PHP
How to use thinkphp5+uploadify for file uploads