Answer the question
In order to leave comments, you need to log in
Where is the right place to set a variable in a session in Yii?
There is a site with subdomains. You need to define a subdomain, find out the region and show information for the corresponding region. Where is it better to check the subdomain and set the value to the session?
Now I have made a separate BaseController class, I check and remember the values of it in init (), I inherit from it in all frontend controllers. It works, but I don't like that I'm inheriting from a new class.
Answer the question
In order to leave comments, you need to log in
Make a service if this data is needed in the future, otherwise the listener.
if component - sample config
return [
'bootstrap' => [
'mySubdomainComponent'
],
'components' => [
'mySubdomainComponent' => '\namespace\of\mySubdomainComponent'
]
];
// обработка данных в компоненте, метод init
...
// в дальнейшем можно получить компонент
\Yii::$app->get('mySubdomainComponent')
$app = \Yii::$app;
$app->on($app::EVENT_BEFORE_REQUEST, ['myListener', 'method']);
// в листенере делаем нужную обработку
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question