2017-07-07 70 views

回答

1

如果你看看@FOSUserBundle/Resources/config/routing/profile.xml,你会看到下面的路线。您可以在自己的路由

<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> 

使用相同的名称在自己的routing.yml覆盖任何路由(或其他配置)你会简单地覆盖这样的:

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 } 

注意,最可能您不再使用默认的ProfileController,而是您自己的ProfileController扩展了FOSUserBundle ProfileController。这就是为什么我也将控制器更改为AppBundle:Profile:edit,但显然这需要匹配您的代码。

还要注意{id}需要在你的代码来实现,例:

public function showAction(Request $request, $id) 

在此还看到一个更详细的解答(另一个途径):How to customize FOS UserBundle URLs