D
D
dllweb2014-11-20 19:34:17
symfony
dllweb, 2014-11-20 19:34:17

How to set listener on all symfony2 requests?

Such a task, there is a mobile site and the main one, the question is how to organize a listener on all actions or requests to the main site, let's say for the first time we went from a mobile device to the main version of the site, we were redirected to the mobile version, but we should also be able to go back to the main one, that is, for example, submit a get request to the main version of the site with the form full.ru/?mobile=off
and put a cookie in the browser of the mobile device, so as not to throw it into the mobile version again. Naturally, you need to check for the presence of this cookie and, for example, its value ...
To organize such a check in the app.php file itself is somehow not competent and probably rude (not according to Feng Shui).
Maybe it can be done somehow through the service by intercepting the event, I'm still poorly versed in all the giblets of symfony2
What do you think?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2017-07-19
@prototype_denis

https://symfony.com/doc/current/event_dispatcher/b...
https://symfony.com/doc/current/event_dispatcher.h...
Listener on kernel.request
In it, write the "mobility" flag to the session
Setting cookies, if needed, then on kernel.response
Get the flag from the session and add it to Response

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question