所以基本上我有一个我想要的捆绑控制器和一个路由前缀,所以我在课堂上使用@Route注释,我已经完成了我的Symfony2应用程序的所有其他控制器。但是这个不考虑前缀,所以不能访问/ admin / users / list上的页面,我只能访问/ list。
这是控制器:
<?php
namespace LanPartyOrg\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use JMS\SecurityExtraBundle\Annotation\PreAuthorize;
/*
* @Route("/admin")
*
*/
class AdminController extends Controller
{
/**
* @Route("/list", name="users_list")
* @Template("LanPartyOrgUserBundle:Admin:List.html.twig")
*/
public function listAction(){
$em = $this->getDoctrine()->getManager();
$users = $em->getRepository('LanPartyOrgUserBundle:User')->findAll();
return array('users'=>$users);
}
}
这是我的routing.yml:
lan_party_org_user:
resource: "@LanPartyOrgUserBundle/Controller/"
type: annotation
prefix: /
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
感谢您的帮助
答案 0 :(得分:3)
必须将注释添加到docblocks,而不仅仅是简单注释。
您需要使用/**
而不是/*
开始发表评论(请注意加倍*
):
/**
* @Route("/admin")
*/
class AdminController extends Controller
{
// ...
}
这将使AdminController
的所有/admin
路线加上前缀。
答案 1 :(得分:2)
您的以下代码
/*
* @Route("/admin")
*
*/
应该是
/**
* @Route("/admin")
*
*/
并确保两个控制器不应具有相同的前缀。