فهرست منبع

Merge pull request #4452 from greg0ire/document_child_admin_routing

Add a tip about clearing parent routes
Jordi Sala Morales 8 سال پیش
والد
کامیت
24cec8a401
2فایلهای تغییر یافته به همراه32 افزوده شده و 0 حذف شده
  1. 3 0
      Resources/doc/conf.py
  2. 29 0
      Resources/doc/reference/architecture.rst

+ 3 - 0
Resources/doc/conf.py

@@ -83,6 +83,9 @@ exclude_patterns = ['_build']
 # The name of the Pygments (syntax highlighting) style to use.
 # The name of the Pygments (syntax highlighting) style to use.
 pygments_style = 'sphinx'
 pygments_style = 'sphinx'
 
 
+# This will be used when using the shorthand notation
+highlight_language = 'php'
+
 # A list of ignored prefixes for module index sorting.
 # A list of ignored prefixes for module index sorting.
 #modindex_common_prefix = []
 #modindex_common_prefix = []
 
 

+ 29 - 0
Resources/doc/reference/architecture.rst

@@ -356,5 +356,34 @@ Then, you have to set the CommentAdmin ``parentAssociationMapping`` attribute to
 
 
 It also possible to set a dot-separated value, like ``post.author``, if your parent and child admins are not directly related.
 It also possible to set a dot-separated value, like ``post.author``, if your parent and child admins are not directly related.
 
 
+Be wary that being a child admin is optional, which means that regular routes
+will be created regardless of whether you actually need them or not. To get rid
+of them, you may override the ``configureRoutes`` method::
+
+    <?php
+    namespace Sonata\NewsBundle\Admin;
+
+    use Sonata\AdminBundle\Route\RouteCollection;
+
+    class CommentAdmin extends AbstractAdmin
+    {
+        protected $parentAssociationMapping = 'post';
+
+        protected function configureRoutes(RouteCollection $collection)
+        {
+            if ($this->isChild()) {
+
+                // This is the route configuration as a child
+                $collection->clearExcept(['show', 'edit']);
+
+                return;
+            }
+
+            // This is the route configuration as a parent
+            $collection->clear();
+
+        }
+    }
+
 .. _`Django Project Website`: http://www.djangoproject.com/
 .. _`Django Project Website`: http://www.djangoproject.com/
 .. _`CRUD`: http://en.wikipedia.org/wiki/CRUD
 .. _`CRUD`: http://en.wikipedia.org/wiki/CRUD