It may be late, but it can help other people.
I ran into the same issue with Symfony and FOSUserBundle.
In the FOSUserBundle profile link:
site_url / profile /
site_url / profile / edit
site_url / profile / switch password
I have an admin panel and toolbars, and I want the links to be in the admin panel
site_url / admin / profile /
site_url / admin / profile / edit
site_url / admin / profile / switch password
and in the user panel
site_url / dashboard / profile /
site_url / dashboard / profile / edit
site_url / dashboard / profile / switch password
To get this behavior, it is very simple without EventListener and TwigExtesion
Here's the solution:
replace
fos_user: resource: "@FOSUserBundle/Resources/config/routing/all.xml"
by
fos_user_security: resource: "@FOSUserBundle/Resources/config/routing/security.xml" fos_user_registration: resource: "@FOSUserBundle/Resources/config/routing/registration.xml" fos_user_resetting: resource: "@FOSUserBundle/Resources/config/routing/resetting.xml" fos_user_change_password: resource: "@FOSUserBundle/Resources/config/routing/change_password.xml" prefix: /{prefix}/profile fos_user_profile: resource: "@FOSUserBundle/Resources/config/routing/profile.xml" prefix: /{prefix}/profile
In the template use:
<a href="{{ path('fos_user_profile_show', {'prefix': 'dashboard'}) }}">Show Profile</a> <a href="{{ path('fos_user_profile_edit', {'prefix': 'dashboard'}) }}">Edit Profile</a> <a href="{{ path('fos_user_change_password', {'prefix': 'dashboard'}) }}">Change Password</a>
Or any other prefix you want
Now, if you use, for example, a link to change the password, you will get this error
During template rendering, an exception was thrown ("Some required parameters are missing (" prefix ") for creating a URL for the route" fos_user_change_password ".") In FOSUserBundle: ChangePassword: changePassword_content.html.twig on line 3.
you can add a prefix to the template as follows:
replace
<form action="{{ path('fos_user_change_password') }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
by
<form action="{{ path('fos_user_change_password', {'prefix': app.request.attributes.get('prefix') }) }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
it will give you this error
Some required parameters are missing ("prefix") for creating the URL for route "fos_user_profile_show".
the final solution I found is to override the controller
just copy the hole in the application controller folder, change the name and replace
if (null === $response = $event->getResponse()) { $url = $this->generateUrl('fos_user_profile_show'); $response = new RedirectResponse($url); }
by
if (null === $response = $event->getResponse()) { $url = $this->generateUrl('fos_user_profile_show',array('prefix'=>$request->get('prefix'))); $response = new RedirectResponse($url); }
in a form in which you donβt need an action, so it will be
<form {{ form_enctype(form) }} method="POST" class="fos_user_change_password">