routing.rst 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Routing
  2. =======
  3. The default routes used in the CRUD controller are accessible through the
  4. ``Admin`` class.
  5. The ``Admin`` class contains two routing method:
  6. * ``getUrls()``: Returns the available routes;
  7. * ``generateUrl($name, $options)``: Generates the related routes.
  8. Routing Definition
  9. ------------------
  10. You can set a ``baseRouteName`` property inside your ``Admin`` class, which
  11. represents the route prefix.
  12. .. code-block:: php
  13. class PostAdmin extends Admin
  14. {
  15. protected $class = 'Application\Sonata\NewsBundle\Entity\Post';
  16. protected $baseRouteName = 'news_post_admin';
  17. }
  18. If no ``baseRouteName`` is defined then the Admin will pick on for you, built on
  19. following format : 'admin_vendor_bundlename_entityname_action'. If the Admin
  20. fails to find the best baseRouteName then a ``RuntimeException`` will
  21. be throw.
  22. The same goes for the ``baseRoutePattern``.
  23. Routing usage
  24. -------------
  25. Inside a CRUD template, a route can be generated by using the ``Admin`` class.
  26. .. code-block:: html
  27. <a href="{{ admin.generateUrl('list') }}">List</a>
  28. <a href="{{ admin.generateUrl('list', params|merge('page': 1) }}">List</a>