Home > Backend Development > PHP Tutorial > Detailed explanation of ThinkPHP5.0 framework controller inheritance base and custom class cases

Detailed explanation of ThinkPHP5.0 framework controller inheritance base and custom class cases

php中世界最好的语言
Release: 2023-03-28 09:20:02
Original
2124 people have browsed it

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';
  }
}
Copy after login

or customize a base controller class Base:

<?php
namespace app\index\controller;
use think\Controller;
class Base extends Controller
{
}
Copy after login

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';
  }
}
Copy after login

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!

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