0
votes

I want to set a prefix for all controllers in the AdminBundle - "/admin". So I did it in routing.yml file:

my_admin:
   prefix: /admin

Then I changed all admin bundle's route names from:

/**
 * @Route("admin/home", name="admin/home")
 */

to

/**
 * @Route("home", name="home")
 */

And the problem is that when I use:

return $this->redirect($this->generateUrl('admin/installation'));

It throws an exception that the route doesn't exist...before setting the prefix it worked. What's wrong?

2
what is the output of "app/console router:debug | grep admin" ?Nicolai Fröhlich

2 Answers

0
votes

Router::generateUrl expects a route name, no route path. So if you want to link to the home route you showed us, you use:

return $this->redirect($this->generateUrl('home'));

The prefix option is about route paths, not about the name of a route.

0
votes

it is because you have no route called admin/installation. Even if you have prefix for whole controller, you have to give unique names to each route.

/**
 * @Route("home", name="admin/home")
 */