May be it's to late, but it can help other people
I'm facing the same problème with Symfony and FOSUserBundle.
In FOSUserBundle the profile link are :
site_url/profile/
site_url/profile/edit
site_url/profile/change-password
I have an admin and dashboard panel, and I want the links to be in admin panel
site_url/admin/profile/
site_url/admin/profile/edit
site_url/admin/profile/change-password
and in the user dashboard
site_url/dashboard/profile/
site_url/dashboard/profile/edit
site_url/dashboard/profile/change-password
To get this behavior it's very simple without EventListener and TwigExtesion
Here 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 a 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 the change password link you will get this error
An exception has been thrown during the rendering of a template ("Some
mandatory parameters are missing ("prefix") to generate a URL for
route "fos_user_change_password".") in
FOSUserBundle:ChangePassword:changePassword_content.html.twig at line
3.
you can add the prefix in the template like so:
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">
this will give you this error
Some mandatory parameters are missing ("prefix") to generate a URL for
route "fos_user_profile_show".
the final solution that I found is to override the controller
just copy the hole controle in your app controller folder,change the namesapce 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 the form you don't need the action so it will be
<form {{ form_enctype(form) }} method="POST" class="fos_user_change_password">