What you need is a logout success handler.
Define the logout handler in the security.yml:
security:
firewalls:
admin_area:
logout:
success_handler: acme.security.logout_success_handler
And the handler goes like this:
namespace Acme\Bundle\SecurityBundle\Handler;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\DependencyInjection\ContainerAware;
class LogoutSuccessHandler extends ContainerAware implements LogoutSuccessHandlerInterface
{
public function onLogoutSuccess(Request $request)
{
// dynamic route logic
return new RedirectResponse($this->container->get('router')->generate('dynamic_route_name'));
}
}
Btw... Please remove the unwanted imports and Hope this helps! :D
Here is the services.yml
services:
acme.security.logout_success_handler:
class: Acme\Bundle\SecurityBundle\Handler\LogoutSuccessHandler
calls:
- [ setContainer, [ @service_container ] ]