1.构造函数: 控制器类必须继承了\think\Controller类,才能使用: 方法_initialize 代码: <?php namespace app\lian\controller; use think\Controller; use think\Db; use think\Request; class Index extends Controller { public function _initialize() { echo 'init|||'; } public function
学习来源与说明 https://www.kancloud.cn/thinkphp/thinkphp5_quickstart 测试与部署均在windows10下进行学习. 快速入门第三节 获取当前的请求信息的四种方案 继承think\Controller <?php namespace app\index\controller; use think\Controller; class Index extends Controller { public function hello($name =
在建立网站的时候,你通常想着把一些共有的方法提取出来,放入一个控制器内,如果你是将业务逻辑写入了构造函数里面,那么就得注意了. 在thinkphp5.0当中,有一个初始化的方法,类似于构造函数,那就是_initialize(). 但是如果你在父类和子类当中同时使用该方法时,会将父类的_initialize()方法覆盖掉. 如下:我贴出部分代码: class Admin extends CommonMethod { private $adminModel; public function _ini