Home  >  Article  >  Backend Development  >  symfony study notes-bundle1

symfony study notes-bundle1

WBOY
WBOYOriginal
2016-07-29 08:57:081063browse

Install a third-party bundle

1. Use Composer to install

composer require friendsofsymfony/user-bundle=》composer require bundelName
bundleName: a. Readme file of the project b. Search Packagist.org on the website

Search for some third-party bundles Packagist.org

The above command will select the most appropriate version for your project. If you need to specify a version, use the command

<span>$ </span>composer require friendsofsymfony/user-bundle <span>"~2.0"</span>
. The command execution is completed, add the content to composer.json, and download the code to the vendor directory.

2. Register in AppKernel

<span>public</span><span>function</span><span>registerBundles</span><span>()</span><span>{</span><span>$bundles</span><span>=</span><span>array</span><span>(</span><span>// ...</span><span>new</span><span>FOS\UserBundle\FOSUserBundle</span><span>(),</span><span>);</span><span>// ...</span><span>}</span>
If you only want to use the bundle in development mode or test mode, the registration method is as follows
<span>class</span><span>AppKernel</span><span>extends</span><span>Kernel</span><span>{</span><span>// ...</span><span>public</span><span>function</span><span>registerBundles</span><span>()</span><span>{</span><span>$bundles</span><span>=</span><span>array</span><span>(</span><span>// ...</span><span>);</span><span>if</span><span>(</span><span>in_array</span><span>(</span><span>$this</span><span>-></span><span>getEnvironment</span><span>(),</span><span>array</span><span>(</span><span>'dev'</span><span>,</span><span>'test'</span><span>)))</span><span>{</span><span>$bundles</span><span>[]</span><span>=</span><span>new</span><span>Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle</span><span>();</span><span>}</span><span>// ...</span><span>}</span><span>}</span>
3, configure bundle

Configure in this file app/config/config.yml

config:dump-reference AsseticBundle
The above command can display the AsseticBundle configuration manual (reference)

The above introduces the symfony study notes-bundle1, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn