浏览代码

Improved routing.rst documentation

Added example of using baseRoutePattern

Added description of how to remove routes only when an Admin is embedded in another Admin
Christian Morgan 12 年之前
父节点
当前提交
59b248817d
共有 1 个文件被更改,包括 36 次插入1 次删除
  1. 36 1
      Resources/doc/reference/routing.rst

+ 36 - 1
Resources/doc/reference/routing.rst

@@ -28,7 +28,22 @@ in the following format: 'admin_vendor_bundlename_entityname_action'. If the
 Admin fails to find the best baseRouteName then a ``RuntimeException`` will
 be thrown.
 
-The same goes for the ``baseRoutePattern``.
+You can also use ``baseRoutePattern`` to set a custom URL for a given ``Admin`` class.
+
+For example, to use ``http://yourdomain.com/admin/foo`` as the base URL for 
+the ``FooAdmin`` class (instead of the default of ``http://yourdomain.com/admin/vendor/bundle/foo``)
+use the following code:
+
+.. code-block:: php
+
+    <?php
+    class FooAdmin extends Admin
+    {
+        protected $baseRouteName = 'foo';
+    }
+
+You will then have route URLs like ``http://yourdomain.com/admin/foo/list`` and 
+``http://yourdomain.com/admin/foo/1/edit``
 
 Routing usage
 -------------
@@ -117,6 +132,26 @@ If you want to remove all default routes, you can use ``clear()`` method.
         }
     }
 
+To prevent some routes from being available when one Admin is embedded inside another one
+(e.g. to remove the "add new" option when you embed ``TagAdmin`` within ``PostAdmin``) you 
+can use ``hasParentFieldDescription()`` to detect this case and remove the routes.
+
+.. code-block:: php
+
+    <?php
+    use Sonata\AdminBundle\Route\RouteCollection;
+
+    class TagAdmin extends Admin
+    {
+        protected function configureRoutes(RouteCollection $collection)
+        {
+            if($this->hasParentFieldDescription()) { // prevent display of "Add new" when embedding this form
+                $collection->remove('create');
+            }
+        }
+    }
+
+
 Persistent parameters
 ---------------------