Rumah > Artikel > pembangunan bahagian belakang > symfony学习笔记-bundle1
安装第三方的bundle
1,使用Composer安装
composer require friendsofsymfony/user-bundle=》composer require bundelNamebundleName怎么来呢:a,项目的readme文件 b,在网站上查找Packagist.org
搜索一些第三方的bundle Packagist.org
上面的命令会为你的项目选择最合适的版本,如果需要制定版本 使用命令
<span>$ </span>composer require friendsofsymfony/user-bundle <span>"~2.0"</span>,命令执行完成,添加内容到
composer.json
,并且下载代码到vendor目录。2,在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>如果只想在开发模式或者测试模式下使用bundle,注册方式如下
<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,配置bundle
在这个文件app/config/config.yml中进行配置
config:dump-reference AsseticBundle上面的命令可以显示AsseticBundle配置的手册(reference)
以上就介绍了symfony学习笔记-bundle1,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。