installation.rst 6.3 KB

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