概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:49:46 | 180 次阅读 | 评论: 0 | 来源: 网络整理

Most bundles provide their own installation instructions. However, the basic steps for installing a bundle are the same:

A) Add Composer Dependencies

Dependencies are managed with Composer, so if Composer is new to you, learn some basics in their documentation. This has 2 steps:

1) Find out the Name of the Bundle on Packagist

The README for a bundle (e.g. FOSUserBundle) usually tells you its name (e.g. friendsofsymfony/user-bundle). If it doesn’t, you can search for the library on the Packagist.org site.

注解

Looking for bundles? Try searching at KnpBundles.com: the unofficial archive of Symfony Bundles.

2) Install the Bundle via Composer

Now that you know the package name, you can install it via Composer:

$ composer require friendsofsymfony/user-bundle

This will choose the best version for your project, add it to composer.json and download the library into the vendor/ directory. If you need a specific version, add a : and the version right after the library name (see composer require).

B) 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 FOSUserBundleFOSUserBundle(),
        );

        // ...
    }
}

C) Configure the Bundle

It’s pretty common for a bundle to need some additional setup or configuration in app/config/config.yml. The bundle’s documentation will tell you about the 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:

$ app/console config:dump-reference AsseticBundle

or this:

$ app/console config:dump-reference assetic

The output will look like this:

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. Have fun!

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务