1

When u visit the /profile path it takes you to a default profile page.

I made changes so when you visit a profile you need to add an id to the url to visit the correct page.

However, the /profile still goes to the default page, how can I disable this route or make it go to a custom path?

Thanks in advance.

Keutelvocht
  • 670
  • 2
  • 10
  • 28

1 Answers1

1

If you look at @FOSUserBundle/Resources/config/routing/profile.xml, you will see the following routings. You can overwrite any routing (or other configuration) by using the same name in your own routing

<route id="fos_user_profile_show" path="/" methods="GET">
    <default key="_controller">FOSUserBundle:Profile:show</default>
</route>

<route id="fos_user_profile_edit" path="/edit" methods="GET POST">
    <default key="_controller">FOSUserBundle:Profile:edit</default>
</route>

In your own routing.yml you'd simply overwrite like this:

fos_user_profile_show:
    path: /profile/{id}
    defaults: { _controller: AppBundle:Profile:show }

fos_user_profile_edit:
    path: /profile/edit/{id}
    defaults: { _controller: AppBundle:Profile:edit }

Note that most likely you are no longer using the default ProfileController, but instead have your own ProfileController extending the FOSUserBundle ProfileController. That's why I also changed the controller to AppBundle:Profile:edit, but obviously this needs to match your code.

Also note the {id} needs to be implemented in your code, ex.:

public function showAction(Request $request, $id)

Also see here for a more detailed answer (for another route): How to customize FOS UserBundle URLs

Rein Baarsma
  • 1,466
  • 13
  • 22