A
A
Artur Kosikov2020-08-02 11:08:22
Yii
Artur Kosikov, 2020-08-02 11:08:22

$_GET parameters not available in Yii2 component?

I create a component and put it in autoload

'bootstrap' => ['setGeo', 'log'],
...
'components' => [
...
   'setGeo' => [
            'class' => 'frontend\components\setGeo',
        ],
...
]
...


In component code I need $_GET parameters

class setGeo extends yii\base\Component
{

    public function init() {

    var_dump(Yii::$app->request->get()); // or var_dump($_GET);

    }
}


But here is an empty array...

In the Yii Controller ::$app->request->get() are available. How can I access the Request component from within my component?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artur Kosikov, 2020-08-02
@atillus

Implemented via behavior

A
Artem, 2020-08-02
@proudmore

Most likely the problem is that the bootstrap section is called before the initialization of the yii\web\Request object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question