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