安裝第三方的bundle
1,使用Composer安裝
composer require friendsofsymfony/user-bundle=》composer require bundelNamebundleName怎麼來呢:a,項目的readme文件 b,在網站上查找Packagist.org
搜尋一些第三方的bundle.上面的指令會為你的專案選擇最適合的版本,如果需要製定版本使用指令
<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教程有興趣的朋友有所幫助。