Переглянути джерело

Merge pull request #479 from maastermedia/doc-refactoring

Documentation refactored
Thomas 13 роки тому
батько
коміт
98fd2dcf17

+ 6 - 6
Resources/doc/index.rst

@@ -1,12 +1,12 @@
 Admin Bundle
 ============
 
-**Warning**: The bundle has been split into 4 bundles :
+**SonataAdminBundle is split into 4 bundles:**
 
-* SonataAdminBundle : the current one, contains core libraries and services
-* `SonataDoctrineORMAdminBundle <https://github.com/sonata-project/SonataDoctrineORMAdminBundle>`_: Integrates the admin bundle with the Doctrine ORM project
-* `SonataDoctrineMongoDBAdminBundle <https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle>`_: Integrates the admin bundle with MongoDB (early stage)
-* `SonataDoctrinePhpcrAdminBundle <https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle>`_: Integrates the admin bundle with PHPCR (early stage)
+* SonataAdminBundle: contains core libraries and services
+* `SonataDoctrineORMAdminBundle <https://github.com/sonata-project/SonataDoctrineORMAdminBundle>`_: Integrates Doctrine ORM project with the core admin bundle
+* `SonataDoctrineMongoDBAdminBundle <https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle>`_: Integrates MongoDB with the core admin bundle (early stage)
+* `SonataDoctrinePhpcrAdminBundle <https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle>`_: Integrates PHPCR with the core admin bundle (early stage)
 
 Reference Guide
 ---------------
@@ -16,7 +16,7 @@ Reference Guide
    :numbered:
 
    reference/installation
-   reference/getting-started
+   reference/getting_started
    reference/configuration
    reference/architecture
    reference/dashboard

+ 0 - 124
Resources/doc/reference/getting-started.rst

@@ -1,124 +0,0 @@
-Getting started with the Sonata Admin
-=====================================
-
-Here is a checklist of what is needed to create an admin interface for one Entity:
-
-**1. Setup the Sonata Admin dependencies.**
-
-See the install documentation. Remember to enable translations.
-
-**2. Setup the dependency to the ORM bundle you want to use.**
-
-Either SonataDoctrineORMAdminBundle, SonataDoctrineMongoDBAdminBundle or SonataDoctrinePhpcrAdminBundle.
-
-**3. Create an Admin class that extends the Sonata admin class**
-
-The easiest way to do this is to extend the Sonata\AdminBundle\Admin\Admin class. Here's an example from the SonataNewsBundle:
-
-::
-   
-   /*
-    * This file is part of the Sonata package.
-    *
-    * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
-    *
-    * For the full copyright and license information, please view the LICENSE
-    * file that was distributed with this source code.
-    */
-   
-   namespace Sonata\NewsBundle\Admin;
-   
-   use Sonata\AdminBundle\Admin\Admin;
-   use Sonata\AdminBundle\Datagrid\ListMapper;
-   use Sonata\AdminBundle\Datagrid\DatagridMapper;
-   use Sonata\AdminBundle\Validator\ErrorElement;
-   use Sonata\AdminBundle\Form\FormMapper;
-   
-   class TagAdmin extends Admin
-   {
-       /**
-        * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
-        * @return void
-        */
-       protected function configureFormFields(FormMapper $formMapper)
-       {
-           $formMapper
-               ->add('name')
-               ->add('enabled', null, array('required' => false))
-           ;
-       }
-   
-       /**
-        * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
-        * @return void
-        */
-       protected function configureDatagridFilters(DatagridMapper $datagridMapper)
-       {
-           $datagridMapper
-               ->add('name')
-               ->add('posts')
-           ;
-       }
-   
-       /**
-        * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
-        * @return void
-        */
-       protected function configureListFields(ListMapper $listMapper)
-       {
-           $listMapper
-               ->addIdentifier('name')
-               ->add('slug')
-               ->add('enabled')
-           ;
-       }
-   
-       /**
-        * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
-        * @param $object
-        * @return void
-        */
-       public function validate(ErrorElement $errorElement, $object)
-       {
-           $errorElement
-               ->with('name')
-                   ->assertMaxLength(array('limit' => 32))
-               ->end()
-           ;
-       }
-   }
-   
-
-
- 
-**4. Link the class to the dashboard.**
- 
-The easiest way to do this is to create a default group in the dashboard config::
-
-    dashboard_groups:
-        default: ~
-        
-**5. Create an admin service**
-
-You need to create a service for the new admin class and link it into the framework by setting the sonata.admin tag.
-
-::
- 
-   
-   <container xmlns="http://symfony.com/schema/dic/services"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
-       <services>
-          <service id="sonata.admin.course" class="YourNS\AdminBundle\Admin\BlogAdmin">
-             <tag name="sonata.admin" manager_type="orm" group="Posts" label="Blog"/>
-             <argument />
-             <argument>YourNS\AdminBundle\Entity\Course</argument>
-             <argument>SonataAdminBundle:CRUD</argument>
-             <call method="setTranslationDomain">
-                 <argument>YourNSAdminBundle</argument>
-             </call>    
-         </service>
-      </services>
-   </container> 
-   
-That should be it!

+ 197 - 0
Resources/doc/reference/getting_started.rst

@@ -0,0 +1,197 @@
+Getting started with SonataAdminBundle
+======================================
+
+After installation of SonataAdminBundle you need to configure it for your models.
+Here is a quick checklist of what is needed to quickly setup SonataAdminBundle
+and create your first admin interface for the models of your application:
+
+* Step 1: Define SonataAdminBundle routes
+* Step 2: Setup the persistence service (ORM, ODM, ...)
+* Step 3: Create admin class
+* Step 4: Create admin service
+* Step 5: Configuration
+* Step 6: Security
+
+
+Step 1: Define SonataAdminBundle routes
+---------------------------------------
+
+SonataAdminBundle contains several routes. Import them by adding the following
+code to your application's routing file:
+
+.. code-block:: yaml
+
+    # app/config/routing.yml
+    admin:
+        resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
+        prefix: /admin
+
+    _sonata_admin:
+        resource: .
+        type: sonata_admin
+        prefix: /admin
+
+.. note::
+
+    If you're using XML or PHP to specify your application's configuration,
+    the above routing configuration must be placed in routing.xml or
+    routing.php according to your format (i.e. XML or PHP).
+
+At this point you can already access the admin dashboard by visiting the url:
+``http://yoursite.local/admin/dashboard``.
+
+
+Step 2: Setup the persistence service (ORM, ODM, ...)
+-----------------------------------------------------
+
+SonataAdminBundle does not impose persistance service (service for handling and
+controlling your models), however most likely your application will use some
+persistance service (like ORM or ODM for database and document stores) therefore
+you can use the following bundles officially supported by Sonata Project's admin
+bundle:
+
+* SonataDoctrineORMAdminBundle
+* SonataDoctrineMongoDBAdminBundle
+* SonataDoctrinePhpcrAdminBundle
+
+Propel users are warmly welcome to contribute and create a new bundle for Propel
+ORM that will integrate in SonataAdminBundle.
+
+Install a persistance servise you need and configure it according to their
+related documentation.
+
+Step 3: Create Admin class
+--------------------------
+
+Admin class represents mapping of your model and administration sections (forms,
+list, show). The easiest way to create an admin class for your model is to extend
+the Sonata\AdminBundle\Admin\Admin class. Here is a simple example from the
+SonataNewsBundle:
+
+.. code-block:: php
+   
+   namespace Sonata\NewsBundle\Admin;
+   
+   use Sonata\AdminBundle\Admin\Admin;
+   use Sonata\AdminBundle\Datagrid\ListMapper;
+   use Sonata\AdminBundle\Datagrid\DatagridMapper;
+   use Sonata\AdminBundle\Validator\ErrorElement;
+   use Sonata\AdminBundle\Form\FormMapper;
+   
+   class TagAdmin extends Admin
+   {
+       protected function configureFormFields(FormMapper $formMapper)
+       {
+           $formMapper
+               ->add('name')
+               ->add('enabled', null, array('required' => false))
+           ;
+       }
+
+       protected function configureDatagridFilters(DatagridMapper $datagridMapper)
+       {
+           $datagridMapper
+               ->add('name')
+               ->add('posts')
+           ;
+       }
+
+       protected function configureListFields(ListMapper $listMapper)
+       {
+           $listMapper
+               ->addIdentifier('name')
+               ->add('slug')
+               ->add('enabled')
+           ;
+       }
+
+       public function validate(ErrorElement $errorElement, $object)
+       {
+           $errorElement
+               ->with('name')
+                   ->assertMaxLength(array('limit' => 32))
+               ->end()
+           ;
+       }
+   }
+
+
+Step 4: Create admin service
+----------------------------
+
+To notify your administration of your new admin class you need to create an
+admin service and link it into the framework by setting the sonata.admin tag.
+
+.. code-block:: xml
+
+   <container xmlns="http://symfony.com/schema/dic/services"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+       <services>
+          <service id="sonata.admin.course" class="YourNS\AdminBundle\Admin\BlogAdmin">
+             <tag name="sonata.admin" manager_type="orm" group="Posts" label="Blog"/>
+             <argument />
+             <argument>YourNS\AdminBundle\Entity\Course</argument>
+             <argument>SonataAdminBundle:CRUD</argument>
+             <call method="setTranslationDomain">
+                 <argument>YourNSAdminBundle</argument>
+             </call>
+         </service>
+      </services>
+   </container>
+
+
+Step 5: Configuration
+---------------------
+
+At this point you have basic administration for your model. If you wish to
+quickly customize your administration you can create some configuration options
+and change them according to your requirements:
+
+.. code-block:: yaml
+
+    # app/config/config.yml
+    sonata_admin:
+        title:      Sonata Project
+        title_logo: /bundles/sonataadmin/logo_title.png
+        templates:
+            # default global templates
+            layout:  SonataAdminBundle::standard_layout.html.twig
+            ajax:    SonataAdminBundle::ajax_layout.html.twig
+
+            # default actions templates, should extend a global templates
+            list:    SonataAdminBundle:CRUD:list.html.twig
+            show:    SonataAdminBundle:CRUD:show.html.twig
+            edit:    SonataAdminBundle:CRUD:edit.html.twig
+        dashboard_groups:
+            default: ~
+
+
+Linking the admin class to the dashboard is done automatically because of the
+default option you defined above:
+
+    dashboard_groups:
+        default: ~
+
+However you can define only admin groups you want to show in the dashboard by:
+
+    dashboard_groups:
+        sonata_page:
+            label: Page
+            items: ~
+
+More information can be found in the configuration chapter of this documentation.
+
+
+Step 6: Security
+----------------
+
+The last important step is security. By default, the SonataAdminBundle does not
+come with any user management for ultimate flexibility, however it is most
+likely your application requires such feature. The Sonata Project includes a
+``SonataUserBundle`` which integrates very popular ``FOSUserBundle``. Please
+refer to the security section of this documentation for more information.
+
+
+That should be it! Read next sections fore more verbose documentation of the
+SonataAdminBundle and how to tweak it for your requirements.

+ 67 - 86
Resources/doc/reference/installation.rst

@@ -1,109 +1,90 @@
 Installation
 ============
 
-Download bundles
-----------------
+Prerequisites
+-------------
 
-To begin, add the dependent bundles to the ``vendor/bundles`` directory. Add
-the following lines to the file ``deps``::
+**Translations**
+If you wish to use default translation texts provided in this bundle, you have
+to make sure you have translator enabled in your config.
 
-  [SonatajQueryBundle]
-      git=http://github.com/sonata-project/SonatajQueryBundle.git
-      target=/bundles/Sonata/jQueryBundle
+.. code-block:: yaml
+
+    # app/config/config.yml
+    framework:
+        translator: ~
+
+
+Installation
+------------
+
+Download SonataAdminBundle and its dependencies to the ``vendor`` directory. You
+can use the Symfony's vendor script for the automated procces. Add the following
+in your ``deps`` file::
 
   [SonataAdminBundle]
       git=http://github.com/sonata-project/SonataAdminBundle.git
       target=/bundles/Sonata/AdminBundle
 
+  [SonatajQueryBundle]
+      git=http://github.com/sonata-project/SonatajQueryBundle.git
+      target=/bundles/Sonata/jQueryBundle
+
   [KnpMenuBundle]
-      git=https://github.com/KnpLabs/KnpMenuBundle.git
+      git=http://github.com/KnpLabs/KnpMenuBundle.git
       target=/bundles/Knp/Bundle/MenuBundle
 
   [KnpMenu]
-      git=https://github.com/KnpLabs/KnpMenu.git
+      git=http://github.com/KnpLabs/KnpMenu.git
       target=/knp/menu
 
-and run::
+and run the vendors script to download bundles::
 
-  bin/vendors install
+  php bin/vendors install
 
-Configuration
--------------
+If you prefer instead to use git submodules, then run the following:
+
+  git submodule add http://github.com/sonata-project/SonataAdminBundle.git vendor/bundles/Sonata/AdminBundle
+  git submodule add http://github.com/sonata-project/SonatajQueryBundle.git vendor/bundles/Sonata/jQueryBundle
+  git submodule add http://github.com/KnpLabs/KnpMenuBundle.git vendor/bundles/Knp/Bundle/MenuBundle
+  git submodule add http://github.com/KnpLabs/KnpMenu.git vendor/knp/menu
+  git submodule update --init
 
-Next, be sure to enable the bundles in your autoload.php and AppKernel.php
+Next, be sure to enable this bundles in your autoload.php and AppKernel.php
 files:
 
 .. code-block:: php
 
-  <?php
-  // app/autoload.php
-  $loader->registerNamespaces(array(
-      // ...
-      'Sonata'     => __DIR__.'/../vendor/bundles',
-      'Knp\Bundle' => __DIR__.'/../vendor/bundles',
-      'Knp\Menu'   => __DIR__.'/../vendor/knp/menu/src',
-      // ...
-  ));
-
-  // app/AppKernel.php
-  public function registerBundles()
-  {
-      return array(
-          // ...
-          new Sonata\jQueryBundle\SonatajQueryBundle(),
-          new Sonata\AdminBundle\SonataAdminBundle(),
-          new Knp\Bundle\MenuBundle\KnpMenuBundle(),
-          // ...
-      );
-  }
-
-The bundle also contains several routes. Import them by adding the following
-code to your application's routing file:
-
-.. code-block:: yaml
-
-    # app/config/routing.yml
-    admin:
-        resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
-        prefix: /admin
-
-    _sonata_admin:
-        resource: .
-        type: sonata_admin
-        prefix: /admin
-
-Now, install the assets from the different bundles:
-``php app/console assets:install web --symlink``.
-At this point you can access the admin dashboard with the url:
-``http://yoursite.local/admin/dashboard``.
-
-.. note::
-
-    If you're using XML or PHP to specify your application's configuration,
-    the above configuration and routing will actually be placed in those
-    files, with the correct format (i.e. XML or PHP).
-
-The last important step is security, please refer to the dedicated section of this documentation.
-
-Users management
-----------------
-
-By default, the AdminBundle does not come with any user management, however it is most likely the application
-requires such feature. The Sonata Project includes a ``SonataUserBundle`` which integrates the ``FOSUserBundle``.
-
-The ``FOSUserBundle`` adds support for a database-backed user system in Symfony2. It provides a flexible framework
-for user management that aims to handle common tasks such as user login, registration and password retrieval.
-
-The ``SonataUserBundle`` is just a thin wrapper to include the ``FOSUserBundle`` into the ``AdminBundle``. The
-``SonataUserBundle`` includes :
-
-* A default login area
-* A default ``user_block`` template which is used to display the current user and the logout link
-* 2 Admin classes : User and Group
-* A default class for User and Group.
-
-There is a little magic in the ``SonataAdminBundle`` if the bundle detects the ``SonataUserBundle`` class, then
-the default ``user_block`` template will be changed to use the one provided by the ``SonataUserBundle``.
-
-The install process is available on the dedicated `SonataUserBundle's documentation area <http://sonata-project.org/bundles/user/master/doc/reference/installation.html>`_
-
+    <?php
+    // app/autoload.php
+    $loader->registerNamespaces(array(
+        // ...
+        'Sonata'     => __DIR__.'/../vendor/bundles',
+        'Knp\Bundle' => __DIR__.'/../vendor/bundles',
+        'Knp\Menu'   => __DIR__.'/../vendor/knp/menu/src',
+        // ...
+    ));
+
+    // app/AppKernel.php
+    public function registerBundles()
+    {
+        return array(
+            // ...
+            new Sonata\AdminBundle\SonataAdminBundle(),
+            new Sonata\jQueryBundle\SonatajQueryBundle(),
+            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
+            // ...
+        );
+    }
+
+Now, install the assets from the bundles:
+``php app/console assets:install web``.
+
+Usually when installing new bundles a good practice is also to delete your cache:
+``php app/console cache:clear``.
+
+
+After you have successfully installed above bundles you need to configure
+SonataAdminBundle for administering your models. All that is needed to quickly
+set up SonataAdminBundle is described in the next chapter the Getting started
+with SonataAdminBundle.

+ 26 - 0
Resources/doc/reference/security.rst

@@ -1,6 +1,32 @@
 Security
 ========
 
+Users management
+----------------
+
+By default, the SonataAdminBundle does not come with any user management, however it is most likely the application
+requires such feature. The Sonata Project includes a ``SonataUserBundle`` which integrates the ``FOSUserBundle``.
+
+The ``FOSUserBundle`` adds support for a database-backed user system in Symfony2. It provides a flexible framework
+for user management that aims to handle common tasks such as user login, registration and password retrieval.
+
+The ``SonataUserBundle`` is just a thin wrapper to include the ``FOSUserBundle`` into the ``AdminBundle``. The
+``SonataUserBundle`` includes :
+
+* A default login area
+* A default ``user_block`` template which is used to display the current user and the logout link
+* 2 Admin classes : User and Group
+* A default class for User and Group.
+
+There is a little magic in the ``SonataAdminBundle`` if the bundle detects the ``SonataUserBundle`` class, then
+the default ``user_block`` template will be changed to use the one provided by the ``SonataUserBundle``.
+
+The install process is available on the dedicated `SonataUserBundle's documentation area <http://sonata-project.org/bundles/user/master/doc/reference/installation.html>`_
+
+
+Security handlers
+-----------------
+
 The security part is managed by a ``SecurityHandler``, the bundle has 2 handlers
 
   - ``sonata.admin.security.handler.acl`` : ACL and ROLES to handle permissions