You are browsing the documentation for Symfony 2.2 which is not maintained anymore.
Consider upgrading your projects to Symfony 5.2.
How to install 3rd party Bundles
How to install 3rd party Bundles¶
Most bundles provide their own installation instructions. However, the basic steps for installing a bundle are the same.
Add Composer Dependencies¶
Starting from Symfony 2.1, dependencies are managed with Composer. It’s a good idea to learn some basics of Composer in their documentation.
Before you can use Composer to install a bundle, you should look for a Packagist package of that bundle. For example, if you search for the popular FOSUserBundle you will find a package called friendsofsymfony/user-bundle.
Note
Packagist is the main archive for Composer. If you are searching
for a bundle, the best thing you can do is check out
KnpBundles, it is the unofficial archive of Symfony Bundles. If
a bundle contains a README
file, it is displayed there and if it
has a Packagist package it shows a link to the package. It’s a
really useful site to begin searching for bundles.
Now that you have the package name, you should determine the version
you want to use. Usually different versions of a bundle correspond to
a particular version of Symfony. This information should be in the README
file. If it isn’t, you can use the version you want. If you choose an incompatible
version, Composer will throw dependency errors when you try to install. If
this happens, you can try a different version.
In the case of the FOSUserBundle, the README
file has a caution that version
1.2.0 must be used for Symfony 2.0 and 1.3+ for Symfony 2.1+. Packagist displays
example require
statements for all existing versions of a package. The
current development version of FOSUserBundle is "friendsofsymfony/user-bundle": "2.0.*@dev"
.
Now you can add the bundle to your composer.json
file and update the
dependencies. You can do this manually:
Add it to the ``composer.json`` file:
1 2 3 4 5 6 7
{ ..., "require": { ..., "friendsofsymfony/user-bundle": "2.0.*@dev" } }
Update the dependency:
1
$ php composer.phar update friendsofsymfony/user-bundle
or update all dependencies
1
$ php composer.phar update
Or you can do this in one command:
1 | $ php composer.phar require friendsofsymfony/user-bundle:2.0.*@dev
|
Enable the Bundle¶
At this point, the bundle is installed in your Symfony project (in
vendor/friendsofsymfony/
) and the autoloader recognizes its classes.
The only thing you need to do now is register the bundle in AppKernel
:
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...,
new FOS\UserBundle\FOSUserBundle(),
);
// ...
}
}
Configure the Bundle¶
Usually a bundle requires some configuration to be added to app’s
app/config/config.yml
file. The bundle’s documentation will likely
describe that configuration. But you can also get a reference of the
bundle’s config via the config:dump-reference
command.
For instance, in order to look the reference of the assetic
config you
can use this:
1 | $ app/console config:dump-reference AsseticBundle
|
or this:
1 | $ app/console config:dump-reference assetic
|
The output will look like this:
1 2 3 4 5 6 7 8 9 10 11 | assetic:
debug: %kernel.debug%
use_controller:
enabled: %kernel.debug%
profiler: false
read_from: %kernel.root_dir%/../web
write_to: %assetic.read_from%
java: /usr/bin/java
node: /usr/local/bin/node
node_paths: []
# ...
|
Other Setup¶
At this point, check the README
file of your brand new bundle to see
what to do next.
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.