1分钟部署网站📞AI智能客服,大模型训练自有数据,简单好用,有效降低客服成本 广告
如果你的控制器类继承了`\think\Controller`类的话,可以定义控制器初始化方法`_initialize`,在该控制器的方法调用之前首先执行。 例如: ~~~ namespace app\index\controller; use think\Controller; class Index extends Controller { public function _initialize() { echo 'init<br/>'; } public function hello() { return 'hello'; } public function data() { return 'data'; } } ~~~ 如果访问 http://localhost/index.php/index/Index/hello 会输出 ~~~ init hello ~~~ 如果访问 http://localhost/index.php/index/Index/data 会输出 ~~~ init data ~~~