installation.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. Installation
  2. ============
  3. SonataAdminBundle is just a bundle and as such, you can install it at any
  4. moment during a project's lifecycle.
  5. 1. Download the Bundle
  6. ----------------------
  7. Open a command console, enter your project directory and execute the
  8. following command to download the latest stable version of this bundle:
  9. .. code-block:: bash
  10. $ composer require sonata-project/admin-bundle
  11. This command requires you to have Composer installed globally, as explained in
  12. the `installation chapter`_ of the Composer documentation.
  13. 1.1. Download a Storage Bundle
  14. ------------------------------
  15. You've now downloaded the SonataAdminBundle. While this bundle contains all
  16. functionality, it needs storage bundles to be able to communicate with a
  17. database. Before using the SonataAdminBundle, you have to download one of these
  18. storage bundles. The official storage bundles are:
  19. * `SonataDoctrineORMAdminBundle`_ (integrates the Doctrine ORM);
  20. * `SonataDoctrineMongoDBAdminBundle`_ (integrates the Doctrine MongoDB ODM);
  21. * `SonataPropelAdminBundle`_ (integrates Propel);
  22. * `SonataDoctrinePhpcrAdminBundle`_ (integrates the Doctrine PHPCR ODM).
  23. You can download them in the same way as the SonataAdminBundle. For instance,
  24. to download the SonataDoctrineORMAdminBundle, execute the following command:
  25. .. code-block:: bash
  26. $ composer require sonata-project/doctrine-orm-admin-bundle
  27. .. tip::
  28. Don't know which to choose? Most new users prefer SonataDoctrineORMAdmin,
  29. to interact with traditional relational databases (MySQL, PostgreSQL, etc).
  30. Step 2: Enable the Bundle
  31. -------------------------
  32. Then, enable the bundle and the bundles it relies on by adding the following
  33. line in the `app/AppKernel.php` file of your project:
  34. .. code-block:: php
  35. // app/AppKernel.php
  36. // ...
  37. class AppKernel extends Kernel
  38. {
  39. public function registerBundles()
  40. {
  41. $bundles = array(
  42. // ...
  43. // The admin requires some twig functions defined in the security
  44. // bundle, like is_granted. Register this bundle if it wasn't the case
  45. // already.
  46. new Symfony\Bundle\SecurityBundle\SecurityBundle(),
  47. // These are the other bundles the SonataAdminBundle relies on
  48. new Sonata\CoreBundle\SonataCoreBundle(),
  49. new Sonata\BlockBundle\SonataBlockBundle(),
  50. new Knp\Bundle\MenuBundle\KnpMenuBundle(),
  51. // And finally, the storage and SonataAdminBundle
  52. new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
  53. new Sonata\AdminBundle\SonataAdminBundle(),
  54. );
  55. // ...
  56. }
  57. // ...
  58. }
  59. .. note::
  60. If a bundle is already registered somewhere in your ``AppKernel.php``, you
  61. should not register it again.
  62. .. note::
  63. Since version 2.3, the bundle comes with jQuery and other front-end
  64. libraries. To update the versions (which isn't required), you can use
  65. `Bower`_. To make sure you get the dependencies that match the version of
  66. SonataAdminBundle you are using, you can make bower use the local bower
  67. dependency file, like this:
  68. .. code-block:: bash
  69. $ bower install ./vendor/sonata-project/admin-bundle/bower.json
  70. Step 3: Configure the Installed Bundles
  71. ---------------------------------------
  72. Now all needed bundles are downloaded and registered, you have to add some
  73. configuration. The admin interface is using SonataBlockBundle to put everything
  74. in blocks. You just have to tell the block bundle about the existence of the
  75. admin block:
  76. .. code-block:: yaml
  77. # app/config/config.yml
  78. sonata_block:
  79. default_contexts: [cms]
  80. blocks:
  81. # enable the SonataAdminBundle block
  82. sonata.admin.block.admin_list:
  83. contexts: [admin]
  84. # ...
  85. .. note::
  86. Don't worry too much if, at this point, you don't yet understand fully
  87. what a block is. The SonataBlockBundle is a useful tool, but it's not vital
  88. that you understand it in order to use the admin bundle.
  89. Step 4: Import Routing Configuration
  90. ------------------------------------
  91. The bundles are now registered and configured correctly. Before you can use it,
  92. the Symfony router needs to know the routes provided by the SonataAdminBundle.
  93. You can do this by importing them in the routing configuration:
  94. .. code-block:: yaml
  95. # app/config/routing.yml
  96. admin_area:
  97. resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
  98. prefix: /admin
  99. Step 5: Enable the "translator" service
  100. ---------------------------------------
  101. The translator service is required by SonataAdmin to display all labels properly.
  102. .. code-block:: yaml
  103. # app/config/config.yml
  104. framework:
  105. translator: { fallbacks: [en] }
  106. Step 6: Preparing your Environment
  107. ----------------------------------
  108. As with all bundles you install, it's a good practice to clear the cache and
  109. install the assets:
  110. .. code-block:: bash
  111. $ php bin/console cache:clear
  112. $ php bin/console assets:install
  113. The Admin Interface
  114. -------------------
  115. You've finished the installation process, congratulations. If you fire up the
  116. server, you can now visit the admin page on http://localhost:8000/admin
  117. .. note::
  118. This tutorial assumes you are using the build-in server using the
  119. ``php bin/console server:start`` (or ``server:run``) command.
  120. .. image:: ../images/getting_started_empty_dashboard.png
  121. As you can see, the admin panel is very empty. This is because no bundle has
  122. provided admin functionality for the admin bundle yet. Fortunately, you'll
  123. learn how to do this in the :doc:`next chapter <creating_an_admin>`.
  124. .. _`installation chapter`: https://getcomposer.org/doc/00-intro.md
  125. .. _SonataDoctrineORMAdminBundle: http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/index.html
  126. .. _SonataDoctrineMongoDBAdminBundle: http://sonata-project.org/bundles/mongo-admin/master/doc/index.html
  127. .. _SonataPropelAdminBundle: http://sonata-project.org/bundles/propel-admin/master/doc/index.html
  128. .. _SonataDoctrinePhpcrAdminBundle: http://sonata-project.org/bundles/doctrine-phpcr-admin/master/doc/index.html
  129. .. _Bower: http://bower.io/