用定义的路径覆盖变量路径
Overwrite variable path with defined path
我正在使用 fos userbundle 为路线 /profile
创建页面。现在我也希望能够看到其他用户的配置文件,所以我创建了自己的控制器生成 /profile/{username}
。
我现在遇到的问题是我不能使用fos userbundle路径/profile/edit
。它确实显示 route:debug
中的路径
有什么方法可以为路由 /profile/edit 设置例外吗?
这是我的控制器:
/**
* @Route("/profile/{username}")
* @Template()
* @Security("has_role('ROLE_USER')")
*/
public function showOtherAction($username){
$em = $this->get('doctrine')->getManager();
$user = $em->getRepository('DigitalArtLabBundle:User')->findOneByUsername($username);
$sessions = $em->getRepository('DigitalArtLabBundle:checkin')->findLastSessions($user->getUsername() );
return $this->render('FOSUserBundle:Profile:show.html.twig', array(
'user' => $user,
'ses' => $sessions
));
}
先谢谢了:)
您应该在包含来自 FOSUserBundle
的路由配置后粘贴该路由的路由配置。然后将使用第一个匹配的路由(来自FOSUserBundle
)。
您的案例 routing.yml
示例:
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
app:
resource: "@AppBundle/Controller/"
type: annotation
请注意:在这种情况下,您不能拥有名称为 "edit" 的用户(以及其他保留的路由路径)。
我正在使用 fos userbundle 为路线 /profile
创建页面。现在我也希望能够看到其他用户的配置文件,所以我创建了自己的控制器生成 /profile/{username}
。
我现在遇到的问题是我不能使用fos userbundle路径/profile/edit
。它确实显示 route:debug
有什么方法可以为路由 /profile/edit 设置例外吗?
这是我的控制器:
/**
* @Route("/profile/{username}")
* @Template()
* @Security("has_role('ROLE_USER')")
*/
public function showOtherAction($username){
$em = $this->get('doctrine')->getManager();
$user = $em->getRepository('DigitalArtLabBundle:User')->findOneByUsername($username);
$sessions = $em->getRepository('DigitalArtLabBundle:checkin')->findLastSessions($user->getUsername() );
return $this->render('FOSUserBundle:Profile:show.html.twig', array(
'user' => $user,
'ses' => $sessions
));
}
先谢谢了:)
您应该在包含来自 FOSUserBundle
的路由配置后粘贴该路由的路由配置。然后将使用第一个匹配的路由(来自FOSUserBundle
)。
您的案例 routing.yml
示例:
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
app:
resource: "@AppBundle/Controller/"
type: annotation
请注意:在这种情况下,您不能拥有名称为 "edit" 的用户(以及其他保留的路由路径)。