2014-12-30 18:23:49 11210次浏览 1条回答 0 悬赏 2 金钱

由于像在A控制器中的__construct()做一些简单的验证,
然后B控制器才是访问的控制器调用parent::__construct()去做通用的验证,
但是会报错,报错如下

PHP Fatal Error – yii\base\ErrorException
Call to a member function getUniqueId() on a non-object

最佳答案

  • fly020212 发布于 2014-12-31 11:25 举报
    /**
     * @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::__construct99.999% 的情况下,你不需要这么做

    你的问题是,在 controler 初始化的时候,做些验证,用 init() 方法就可以了

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
hiho
职场新人

hiho

注册时间:2014-12-30
最后登录:2015-02-12
在线时长:4小时30分
  • 粉丝0
  • 金钱18
  • 威望0
  • 积分58

热门问题