yii2.0如何用B控制器继承A,A控制器继承yii\web\Controller [ 2.0 版本 ]
由于像在A控制器中的__construct()做一些简单的验证,
然后B控制器才是访问的控制器调用parent::__construct()去做通用的验证,
但是会报错,报错如下
PHP Fatal Error – yii\base\ErrorException
Call to a member function getUniqueId() on a non-object
最佳答案
-

/** * @param string $id the ID of this controller. * @param Module $module the module that this controller belongs to. * @param array $config name-value pairs that will be used to initialize the object properties. */ public function __construct($id, $module, $config = []) { $this->id = $id; $this->module = $module; parent::__construct($config); }yii框架需要自己创建Controller的实例,你任何时候都不需要覆盖人家的构造函数,如果你需要覆盖的话,也需要和它的方法签名一样,并且调用parent::__construct,99.999%的情况下,你不需要这么做你的问题是,在
controler初始化的时候,做些验证,用init()方法就可以了
其他 0 个回答
没有找到数据。
hiho
注册时间:2014-12-30
最后登录:2015-02-12
在线时长:4小时30分
最后登录:2015-02-12
在线时长:4小时30分
- 粉丝0
- 金钱18
- 威望0
- 积分58