routing.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 must set a ``base_route`` property inside your ``Admin`` class, which
  11. represents the each route prefix.
  12. .. code-block:: php
  13. class PostAdmin extends Admin
  14. {
  15. protected $class = 'Application\NewsBundle\Entity\Post';
  16. protected $base_route = 'news_post_admin';
  17. }
  18. This definition is mandatory.
  19. .. code-block:: xml
  20. <?xml version="1.0" encoding="UTF-8" ?>
  21. <routes xmlns="http://www.symfony-project.org/schema/routing"
  22. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  23. xsi:schemaLocation="http://www.symfony-project.org/schema/routing http://www.symfony-project.org/schema/routing/routing-1.0.xsd">
  24. <!-- NEWS CONTROLLER -->
  25. <route id="news_post_admin_list" pattern="/post">
  26. <default key="_controller">NewsBundle:PostAdmin:list</default>
  27. </route>
  28. <route id="news_post_admin_create" pattern="/post/create">
  29. <default key="_controller">NewsBundle:PostAdmin:create</default>
  30. </route>
  31. <route id="news_post_admin_batch" pattern="/post/batch">
  32. <default key="_controller">NewsBundle:PostAdmin:batch</default>
  33. </route>
  34. <route id="news_post_admin_update" pattern="/post/update">
  35. <default key="_controller">NewsBundle:PostAdmin:update</default>
  36. </route>
  37. <route id="news_post_admin_edit" pattern="/post/:id/edit">
  38. <default key="_controller">NewsBundle:PostAdmin:edit</default>
  39. </route>
  40. <route id="news_post_admin_delete" pattern="/post/:id/delete">
  41. <default key="_controller">NewsBundle:PostAdmin:delete</default>
  42. </route>
  43. </routes>
  44. Routing usage
  45. -------------
  46. Inside a CRUD template, a route can be generated by using the ``Admin`` class.
  47. .. code-block:: html
  48. <a href="{{ configuration.generateUrl('list') }}">List</a>
  49. <a href="{{ configuration.generateUrl('list', params|merge('page': 1) }}">List</a>