12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- Routing
- =======
- The default routes used in the CRUD controller are accessible through the
- ``Admin`` class.
- The ``Admin`` class contains two routing method:
- * ``getRoutes()``: Returns the available routes;
- * ``generateUrl($name, $options)``: Generates the related routes.
- Routing Definition
- ------------------
- You can set a ``baseRouteName`` property inside your ``Admin`` class, which
- represents the route prefix.
- .. code-block:: php
- class PostAdmin extends Admin
- {
- protected $baseRouteName = 'news_post_admin';
- }
- If no ``baseRouteName`` is defined then the Admin will pick on for you, built on
- following format : 'admin_vendor_bundlename_entityname_action'. If the Admin
- fails to find the best baseRouteName then a ``RuntimeException`` will
- be throw.
- The same goes for the ``baseRoutePattern``.
- Routing usage
- -------------
- Inside a CRUD template, a route can be generated by using the ``Admin`` class.
- .. code-block:: html
- <a href="{{ admin.generateUrl('list') }}">List</a>
- <a href="{{ admin.generateUrl('list', params|merge('page': 1) }}">List</a>
- Create a route
- --------------
- You can easily register new routes by defining them in the ``Admin`` class. Only Admin routes should be register this
- way. Of course this require to have the related action defined in the controller.
- A route is always generated with the ``Admin`` context, that is why a route can be only defined by its name.
- .. code-block:: php
- use Sonata\AdminBundle\Route\RouteCollection;
-
- class MediaAdmin extends Admin
- {
- public function configureRoutes(RouteCollection $collection)
- {
- $collection->add('duplicate');
- $collection->add('view', $this->getRouterIdParameter().'/view');
- }
- }
- Persistent parameters
- ---------------------
- In some cases, the interface might required to pass the same parameters across the different ``Admin``'s actions.
- Instead of settings them in the template or doing other weird hacks, you can defined a ``getPersistentParameters``
- method. This method will be used when a link is being generated.
- .. code-block:: php
- class MediaAdmin extends Admin
- {
- public function getPersistentParameters()
- {
- if(!$this->getRequest()) {
- return array();
- }
- return array(
- 'provider' => $this->getRequest()->get('provider'),
- 'context' => $this->getRequest()->get('context', 'default'),
- );
- }
- }
- // the result :
- // $admin->generateUrl('create') => /admin/module/create?context=default
|