thinkphp5框架实现的自定义扩展类操作示例
本例详解基于ThinkPHP5框架的自定义扩展类编写方式,提供具体操作步骤供开发者参考。
首先,需在项目根目录下的extend文件夹内新建用于存放扩展类的文件,具体位置可参考图示。

接着,在该文件中编写扩展类的具体逻辑代码。
<?php
namespace org;
/**
*
*/
class Auth
{
public function __construct()
{
# code...
}
public function xx() {
echo 'xxxxxxxxxxxxxx';
}
}
随后,在对应的控制器文件中引入并调用上述定义的扩展类。
<?php
namespace app\index\controller;
use think\Controller;
use org\Auth; //引入扩展类
class Index extends Controller
{
public function index()
{
$a = new Auth();
$a->xx();
}
}
执行后,控制台或页面将输出如下结果:
xxxxxxxxxxxxxx
期望该示例能为使用ThinkPHP框架进行PHP开发的读者提供有益帮助。