S
S
symnoob2018-05-26 22:49:16
symfony
symnoob, 2018-05-26 22:49:16

Symfony 4 - How to make a redirect in a Service?

Good afternoon Forum!
How to make a redirect in the Service, something like: header("Location: www.example.com "); ?

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;

....
class Navbar
{
  public function do_redirect($id){
    return new RedirectResponse($this->router->generate('account_rent_objekt_index'));
  }
}

nothing happens, not even an error :-(
the method is naturally called

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2018-05-26
@voronkovich

Make a subscriber to the 'kernel.request' event. See https://symfony.com/doc/current/components/http_ke...
You can see an example in the demo application: https://github.com/symfony/demo/blob/master/src/Ev...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question