installation.rst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. .. note::
  71. You must enable translator service in `config.yml`.
  72. .. code-block:: yaml
  73. framework:
  74. translator: { fallbacks: ["%locale%"] }
  75. For more information: http://symfony.com/doc/current/translation.html#configuration
  76. Step 3: Configure the Installed Bundles
  77. ---------------------------------------
  78. Now all needed bundles are downloaded and registered, you have to add some
  79. configuration. The admin interface is using SonataBlockBundle to put everything
  80. in blocks. You just have to tell the block bundle about the existence of the
  81. admin block:
  82. .. code-block:: yaml
  83. # app/config/config.yml
  84. sonata_block:
  85. default_contexts: [cms]
  86. blocks:
  87. # enable the SonataAdminBundle block
  88. sonata.admin.block.admin_list:
  89. contexts: [admin]
  90. # ...
  91. .. note::
  92. Don't worry too much if, at this point, you don't yet understand fully
  93. what a block is. The SonataBlockBundle is a useful tool, but it's not vital
  94. that you understand it in order to use the admin bundle.
  95. Step 4: Import Routing Configuration
  96. ------------------------------------
  97. The bundles are now registered and configured correctly. Before you can use it,
  98. the Symfony router needs to know the routes provided by the SonataAdminBundle.
  99. You can do this by importing them in the routing configuration:
  100. .. code-block:: yaml
  101. # app/config/routing.yml
  102. admin_area:
  103. resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
  104. prefix: /admin
  105. Step 5: Enable the "translator" service
  106. ---------------------------------------
  107. The translator service is required by SonataAdmin to display all labels properly.
  108. .. code-block:: yaml
  109. # app/config/config.yml
  110. framework:
  111. translator: { fallbacks: [en] }
  112. Step 6: Preparing your Environment
  113. ----------------------------------
  114. As with all bundles you install, it's a good practice to clear the cache and
  115. install the assets:
  116. .. code-block:: bash
  117. $ php bin/console cache:clear
  118. $ php bin/console assets:install
  119. The Admin Interface
  120. -------------------
  121. You've finished the installation process, congratulations. If you fire up the
  122. server, you can now visit the admin page on http://localhost:8000/admin
  123. .. note::
  124. This tutorial assumes you are using the build-in server using the
  125. ``php bin/console server:start`` (or ``server:run``) command.
  126. .. image:: ../images/getting_started_empty_dashboard.png
  127. As you can see, the admin panel is very empty. This is because no bundle has
  128. provided admin functionality for the admin bundle yet. Fortunately, you'll
  129. learn how to do this in the :doc:`next chapter <creating_an_admin>`.
  130. .. _`installation chapter`: https://getcomposer.org/doc/00-intro.md
  131. .. _SonataDoctrineORMAdminBundle: http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/index.html
  132. .. _SonataDoctrineMongoDBAdminBundle: http://sonata-project.org/bundles/mongo-admin/master/doc/index.html
  133. .. _SonataPropelAdminBundle: http://sonata-project.org/bundles/propel-admin/master/doc/index.html
  134. .. _SonataDoctrinePhpcrAdminBundle: http://sonata-project.org/bundles/doctrine-phpcr-admin/master/doc/index.html
  135. .. _Bower: http://bower.io/