Reputation: 11
I have created component and added in bootstrap. This is my config:
'bootstrap' => ['setGeo', 'log'],
...
'components' => [
...
'setGeo' => [
'class' => 'frontend\components\setGeo',
],
...
]
...
In my component I need $_GET variables
class setGeo extends yii\base\Component
{
public function init() {
var_dump(Yii::$app->request->get()); // or var_dump($_GET);
}
}
But I get array(0) { } in result...
How can I get $_GET params array in my Component?
Upvotes: 0
Views: 40
Reputation: 22144
You have added your component to bootstrap
, it means that it will be initialized at the begging of app lifetime, before request is processed and GET params are extracted for path. I'm not sure what your component is trying to do, but using bootstrap
is probably the wrong way to trigger it. I suggest to use Application::EVENT_AFTER_REQUEST
to trigger this task, GET params should be available at this point.
Upvotes: 1