knp_menu.rst 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. KnpMenu
  2. =======
  3. The admin comes with `KnpMenu <https://github.com/KnpLabs/KnpMenu>`_ integration
  4. It integrates a menu with the KnpMenu library. This menu can be a SonataAdmin service or a route of a custom controller.
  5. Add a custom controller entry in the menu
  6. -----------------------------------------
  7. To add a custom controller entry in the admin menu:
  8. Create your controller
  9. .. code-block:: php
  10. /**
  11. * @Route("/blog", name="blog_home")
  12. */
  13. public function blogAction()
  14. {
  15. // ...
  16. }
  17. /**
  18. * @Route("/blog/article/{articleId}", name="blog_article")
  19. */
  20. public function ArticleAction($articleId)
  21. {
  22. // ...
  23. }
  24. Add the controller route as an item of the menu
  25. .. code-block:: yaml
  26. # Default configuration for "SonataAdminBundle"
  27. sonata_admin:
  28. dashboard:
  29. groups:
  30. news:
  31. label: ~
  32. label_catalogue: ~
  33. items:
  34. - sonata.news.admin.post
  35. - route: blog_home
  36. label: Blog
  37. - route: blog_article
  38. route_params: { articleId: 3 }
  39. label: Article
  40. ...
  41. Also you can override the template of knp_menu used by sonata. The default one is `SonataAdminBundle:Menu:sonata_menu.html.twig`:
  42. .. code-block:: yaml
  43. # Default configuration for "SonataAdminBundle"
  44. sonata_admin:
  45. templates:
  46. knp_menu_template: ApplicationAdminBundle:Menu:custom_knp_menu.html.twig
  47. ...
  48. And voilà, now you have a new menu group which contains an entry to sonata_admin_id, to your blog and to a specific article.