May I perform redirection to another controller within service?
I have implemented a service based on example provided by @Artamiel.
My function code which i
I am agree with @Moritz that redirections must be done inside controllers.
But sometimes happens that some redirection would be useful if done from a local function inside a controller.
In this case a solution could be to create a custom Exception Class (RedirectException).
Here you are a link to an interesting post: https://www.trisoft.ro/blog/56-symfony-redirecting-from-outside-the-controller.
I know it's debatable, but has sense if it's used within a local function inside its Controller.
To summarize, the steps would be:
1) Create a RedirectException class
2) Create a Kernel Listener
3) Set Up the Service in the configuration service file (service.yml)
4) Throw an exception with the url to redirect when necessary.