Missing argument 2 for yii\base\Controller::__construct()

My rest controller is extending from ActiveController. I want to do some initialization in my __construct. I have done this:


class BaseController extends ActiveController

{

    public function __construct($config = [])

    {

        // my code 

        

        parent::__construct($config);

    }

}



I get this error: Missing argument 2 for yii\base\Controller::__construct()

When I look at http://www.yiiframework.com/doc-2.0/yii-rest-activecontroller.html I do not see that overriding constructor require some second params.

btw, my BaseController is inside module.

What I am supposed to do here ?

ActiveController extends yii/rest/Controller that extends yii/web/Controller that in turn extends yii/Base/Controller that has a __construct with 3 parameters

http://www.yiiframework.com/doc-2.0/yii-base-controller.html#__construct()-detail

Thanks, and how do I get these two: $id, $module ?

This didn’t worked :


    public function __construct($config = [])

    {

        // code

         

       parent::__construct($this->id, $this->module, $config);

    }

Do you get the same error? What is the line of code that fires the error?

I dont get same error, I dont even know what the real errors is, since I get crazy big messed output that is hard to read. I have spoted PHP warning:


PHP Warning</span>

                &ndash; <a href="http://www.yiiframework.com/doc-2.0/yii-base-errorexception.html" target="_blank">yii\base\ErrorException</a></h1><h2>Invalid argument supplied for foreach()</h2></div><div class="call-stack"><ul><li class="application call-stack-item"

    data-line="9"><div class="element-wrap"><div class="element"><span class="item-number">1.</span><span class="text">in /var/www/html/www.example.com/api/vendor/yiisoft/yii2/BaseYii.php</span><span class="at">

                at line                <span class="line">520</span></span></div></div><div class="code-wrap"><div class="error-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="hover-line"></div><div class="code"><span class="lines-item">511</span><span class="lines-item">512</span><span class="lines-item">513</span><span class="lines-item">514</span><span class="lines-item">515</span><span class="lines-item">516</span><span class="lines-item">517</span><span class="lines-item">518</span><span class="lines-item">519</span><span class="lines-item">520</span><span class="lines-item">521</span><span class="lines-item">522</span><span class="lines-item">523</span><span class="lines-item">524</span><span class="lines-item">525</span><span class="lines-item">526</span><span class="lines-item">527</span><span class="lines-item">528</span><span class="lines-item">529</span><pre>

My code to aside. Is there any guide that explains how to override constuctor of ActiveController derived class ?

Like: when you want to override __constuct() method of our ActiveController you do this: //explanation.

EDIT: I am doing everything like in this guide: http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html

So I have v1 module and BaseController that extends from ActiveController. And all I want to do is to set some initialization inside constructor of BaseController. Idk why is this so hard.

I am using init() method to do what I wanted, since I can not make it work in constructor:


    public function init()

    {

        $this->_params = Yii::$app->request->queryParams;

    }

yes, I just wanted to suggest init()… it’s a better choice in your case