我正在学习并开始使用KnpMenu包。我读到“.当前类由uri.添加到”当前“菜单项”,但我不知道这到底意味着什么。我试过这样的2项菜单:
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{和
**
* Controller used to manage blog contents in the backend.
*
* @Route("/admin/post")
* @Security("has_role('ROLE_ADMIN')")
*
*/
class BlogController extends Controller
{
/**
* Lists all Post entities.
*
* @Route("/", name="admin_index")
* @Route("/", name="admin_post_index")
* @Method("GET")
*/
public function indexAction()
{使用下面的构建器
public function mainMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root');
$menu->addChild('Home', array('route' => 'homepage'));
$menu->addChild('Blog', array('route' => 'admin_post_index'));
return $menu;
}当我选择主页时,li元素有一个first和一个current类属性--这是很好的-,但是当我选择博客页面时,li元素只有最后一个类属性,而没有当前类属性。我不明白为什么?
发布于 2016-07-22 08:53:36
这可能是由于您在BlogController中具有相同的URL BlogController的多条路由造成的。
* @Route("/", name="admin_index")
* @Route("/", name="admin_post_index")如果您有相同的URL,则不需要多个路由,只需重用相同的路由即可。
https://stackoverflow.com/questions/38520186
复制相似问题