|
| 1 | +.. index:: |
| 2 | + single: Bundle; Installation |
| 3 | + |
| 4 | +How to install 3rd party bundles |
| 5 | +================================ |
| 6 | + |
| 7 | +Most bundles provide a documentation of installation. However, most |
| 8 | +steps are common for any bundle. |
| 9 | + |
| 10 | +Add composer dependencies |
| 11 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 12 | + |
| 13 | +Starting from Symfony2.1 dependencies are managed via Composer. It's |
| 14 | +a good idea to learn some basics of Composer here: |
| 15 | +http://getcomposer.org/doc/00-intro.md. |
| 16 | + |
| 17 | +Before you can use composer to install a bundle you should look for a |
| 18 | +`Packagist`_ package of that bundle. For example, for the |
| 19 | +`FOSUserBundle`_ you should look for a |
| 20 | +``friendsofsymfony/user-bundle`` package and it does exists: |
| 21 | +https://packagist.org/packages/friendsofsymfony/user-bundle. |
| 22 | + |
| 23 | +.. note:: |
| 24 | + |
| 25 | + Packagist is the main archive for Composer. If you are searching |
| 26 | + for a bundle, the best thing you can do is check out |
| 27 | + `KnpBundles`_, it is the unofficial achive of Symfony Bundles. If |
| 28 | + a bundle contains a README file, it is displayed there and if it |
| 29 | + has a Packagist package it shows a link to the package. It's a |
| 30 | + really usefull site to begin searching for bundles. |
| 31 | + |
| 32 | +Now you have the package name, you should determine the version you |
| 33 | +want to use. Usually different versions of a bundle correspond to a |
| 34 | +particular version of Symfony, this should be in the README file (in |
| 35 | +the Package, which you can view on Github or KnpBundles). If it isn't |
| 36 | +in the README, you can use the version you want. In the case of |
| 37 | +FOSUserBundle README file has a caution that version 1.2.0 must be |
| 38 | +used for Symfony2.0 and 1.3 for Symfony2.1+. Let's use development |
| 39 | +version for this exmaple. |
| 40 | + |
| 41 | +Now we can add the bundle to our composer.json file and update the |
| 42 | +dependencies. You can do this manually: |
| 43 | + |
| 44 | +1. **Add it to the ``composer.json`` file:** |
| 45 | + |
| 46 | + .. code-block:: javascript |
| 47 | +
|
| 48 | + { |
| 49 | + ..., |
| 50 | + "require": { |
| 51 | + ..., |
| 52 | + "friendsofsymfony/user-bundle": "dev-master" |
| 53 | + } |
| 54 | + } |
| 55 | +
|
| 56 | +2. **Update the dependency:** |
| 57 | + |
| 58 | + .. code-block:: bash |
| 59 | +
|
| 60 | + $ php composer.phar update friendsofsymfony/user-bundle |
| 61 | +
|
| 62 | + or update all dependencies |
| 63 | + |
| 64 | + .. code-block:: bash |
| 65 | +
|
| 66 | + $ php composer.phar update |
| 67 | +
|
| 68 | +Or you can do this in one command: |
| 69 | + |
| 70 | +.. code-block:: bash |
| 71 | +
|
| 72 | + $ php composer.phar require friendsofsymfony/user-bundle:dev-master |
| 73 | +
|
| 74 | +Enable the bundle |
| 75 | +~~~~~~~~~~~~~~~~~ |
| 76 | + |
| 77 | +Now the bundle is installed into our Symfony project (in |
| 78 | +vendor/friendsofsymfony/) and the autoloader recognises this |
| 79 | +bundle. The only thing we need to do now is registering the bundle in |
| 80 | +the AppKernel: |
| 81 | + |
| 82 | +.. code-block:: php |
| 83 | +
|
| 84 | + // app/AppKernel.php |
| 85 | +
|
| 86 | + // ... |
| 87 | + class AppKernel extends Kernel |
| 88 | + { |
| 89 | + // ... |
| 90 | +
|
| 91 | + public function registerBundles() |
| 92 | + { |
| 93 | + $bundles = array( |
| 94 | + ..., |
| 95 | + new FOS\UserBundle\FOSUserBundle(), |
| 96 | + ); |
| 97 | +
|
| 98 | + // ... |
| 99 | + } |
| 100 | + } |
| 101 | +
|
| 102 | +Configure the bundle |
| 103 | +~~~~~~~~~~~~~~~~~~~~ |
| 104 | + |
| 105 | +Usually bundles require some configuration to be added to app's |
| 106 | +app/config/config.yml file. Bundle's documentation will likely |
| 107 | +describe that configuration. But you can also get a reference of the |
| 108 | +bundle's config via ``config:dump-reference`` command. |
| 109 | + |
| 110 | +For instance, in order to look the reference of the assetic config we |
| 111 | +can use this: |
| 112 | + |
| 113 | +.. code-block:: bash |
| 114 | +
|
| 115 | + $ app/console config:dump-reference AsseticBundle |
| 116 | +
|
| 117 | +or this: |
| 118 | + |
| 119 | +.. code-block:: bash |
| 120 | +
|
| 121 | + $ app/console config:dump-reference assetic |
| 122 | +
|
| 123 | +The output will look like this: |
| 124 | + |
| 125 | +.. code-block:: text |
| 126 | +
|
| 127 | + assetic: |
| 128 | + debug: %kernel.debug% |
| 129 | + use_controller: |
| 130 | + enabled: %kernel.debug% |
| 131 | + profiler: false |
| 132 | + read_from: %kernel.root_dir%/../web |
| 133 | + write_to: %assetic.read_from% |
| 134 | + java: /usr/bin/java |
| 135 | + node: /usr/local/bin/node |
| 136 | + node_paths: [] |
| 137 | + ... |
| 138 | +
|
| 139 | +.. _Packagist: https://packagist.org |
| 140 | +.. _FOSUserBundle: https://github.com/FriendsOfSymfony/FOSUserBundle |
| 141 | +.. _KnpBundles: http://knpbundles.com/ |
0 commit comments