如何在thinkphp5框架中自定义一个扩展类

今天就跟大家聊聊有关如何在thinkphp5框架中自定义一个扩展类,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

1.在extend目录下新建要定义的扩展类:如下图所示

如何在thinkphp5框架中自定义一个扩展类

2.定义扩展类的内容

<?php
  namespace org;
  /**
  *
  */
  class Auth
  {
    public function __construct()
    {
      # code...
    }
    public function xx() {
      echo 'xxxxxxxxxxxxxx';
    }
  }

3.在控制器中调用自定义的扩展类

<?php
namespace app\index\controller;
use think\Controller;
use org\Auth;  //引入扩展类
class Index extends Controller
{
  public function index()
  {
    $a = new Auth();
    $a->xx();
  }
}

4.结果如下

xxxxxxxxxxxxxx

看完上述内容,你们对如何在thinkphp5框架中自定义一个扩展类有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。