How to redirect with flash message when ‘object not found by the @ParamConverter annotation’ Symfony 4 Annotations [duplicate]

So, I’ve seen a lot of posts regarding this topic, but in my case it works perfectly, the only problem is that I don’t know how to instead of getting the error page, just redirect to the admin page where it shows every object of that type (in my case an user).

Here is my code:

     * @Route("/admin/usuario/{cargo}", name="app_admin_usuario_show")
    public function show(User $user)
        if (!$user)
            $this->addFlash('danger', 'El usuario no ha sido encontrado');
        return $this->render('user_admin/show.html.twig', [
           'user' => $user

As you can see I am trying to do it with the !$user but I can’t manage to achieve it.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *