Hi!
Maybe I cannot see the wood for the trees…
I have an ApplicationController, which extends yii\web\Controller and is extended by all other Controllers.
In the init() a Cookie is set, when it’s called for the first time:
[…]
if($calledFirstTime) {
Yii::$app->response->cookies->add(new Cookie([‘name’ => ‘theName’, ‘value’ => ‘theValue’));
}
[…]
I have verified, that this code is only called once. I can see the Cookie in the Set-Cookie header of the response. The weird thing is, it remains in the reponse. Looking at the following requests, the cookie still is in the response header, but not in the request. Therefore
Yii::$app->request->cookies->getValue(‘theName’);
does nothing.
Btw, setting and getting cookies works like a charm in actions. Is there something special about init()/constructor?!
What am I doing wrong? Thanks for your help!