I'm working with Symfony 2.1. I want to setup a redirect routine depending on User is logged in or not. The way I check it is $User->isLoggedIn() where User is a service.
I want to do this before a controller executes. I have few other things happening just before Controller executes. I use event: kernel.controller of kernel.event_listener to do those things. But I realized that I can not redirect to a URL using this event.
I understand I need to use event: kernel.request of kernel.event_listener to be able to redirect to a URL.
Problem. I use the following logic to figure out whether I need to redirect or not.
if (!$controller[0] instanceof NoLogInNeededInterface) {
if (!$User->isLoggedIn()) {
//redirect here
}
}
So, in the kernel.request event, $controler[0] is not available. In the kernel.controller event, response can't be set (will be ignored).
Has anyone got same problem and solved. Or is there any better way of doing, what I'm trying to do?