installation.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. Installation
  2. ============
  3. Make sure you have ``Sonata`` and ``Knplabs`` exists, if not create them::
  4. mkdir src/Sonata
  5. mkdir src/Knplabs
  6. To begin, add the dependent bundles to the ``src/`` directory. If using
  7. git, you can add them as submodules::
  8. git submodule add git@github.com:sonata-project/jQueryBundle.git src/Sonata/jQueryBundle
  9. git submodule add git@github.com:sonata-project/BluePrintBundle.git src/Sonata/BluePrintBundle
  10. git submodule add git@github.com:sonata-project/BaseApplicationBundle.git src/Sonata/BaseApplicationBundle
  11. git submodule add git@github.com:sonata-project/MenuBundle.git src/Knplabs/MenuBundle
  12. Next, be sure to enable the bundles in your application kernel:
  13. .. code-block:: php
  14. // app/autoload.php
  15. $loader->registerNamespaces(array(
  16. // ...
  17. 'Sonata' => __DIR__.'/../src',
  18. 'Knplabs' => __DIR__.'/../src',
  19. // ...
  20. ));
  21. // app/AppKernel.php
  22. public function registerBundles()
  23. {
  24. return array(
  25. // ...
  26. new Sonata\jQueryBundle\SonatajQueryBundle(),
  27. new Sonata\BluePrintBundle\SonataBluePrintBundle(),
  28. new Sonata\BaseApplicationBundle\SonataBaseApplicationBundle(),
  29. new Knplabs\MenuBundle\KnplabsMenuBundle(),
  30. // ...
  31. );
  32. }
  33. Configuration
  34. -------------
  35. To use the ``BaseApplicationBundle``, add the following to your application
  36. configuration file.
  37. .. code-block:: yaml
  38. # app/config/config.yml
  39. sonata_base_application: ~
  40. menu.twig: ~
  41. The bundle also contains several routes. Import them by adding the following
  42. code to your application's routing file:
  43. - Add the BaseApplicationBundle's routing definition
  44. .. code-block:: yaml
  45. # app/config/routing.yml
  46. base_application:
  47. resource: '@SonataBaseApplicationBundle/Resources/config/routing/sonata_base_application.xml'
  48. prefix: /admin
  49. _sonata_base_application:
  50. resource: .
  51. type: sonata_base_application
  52. prefix: /admin
  53. At this point you can access to the dashboard with the url: ``http://yoursite.local/admin/dashboard``.
  54. .. note::
  55. If you're using XML or PHP to specify your application's configuration,
  56. the above configuration and routing will actually be placed in those
  57. files, with the correct format (i.e. XML or PHP).
  58. Declaring new Entity
  59. --------------------
  60. Once you have created an admin class, you must declare the class to use it. Like ::
  61. .. code-block:: yaml
  62. # app/config/config.yml
  63. sonata_base_application:
  64. entities:
  65. post:
  66. label: Post
  67. group: blog
  68. class: Sonata\NewsBundle\Admin\PostAdmin
  69. entity: Application\Sonata\NewsBundle\Entity\Post
  70. controller: SonataNewsBundle:PostAdmin
  71. tag:
  72. label: Tag
  73. group: blog
  74. class: Sonata\NewsBundle\Admin\TagAdmin
  75. entity: Application\Sonata\NewsBundle\Entity\Tag
  76. controller: SonataNewsBundle:TagAdmin
  77. comment:
  78. label: Comment
  79. group: blog
  80. class: Sonata\NewsBundle\Admin\CommentAdmin
  81. entity: Application\Sonata\NewsBundle\Entity\Comment
  82. controller: SonataNewsBundle:CommentAdmin