Symfony2安裝第三方Bundles執行個體詳解_php執行個體

來源:互聯網
上載者:User
本文執行個體講述了Symfony2安裝第三方Bundles的方法。分享給大家供大家參考,具體如下:

大多數的Bundles都提了安裝的介紹,下面來介紹基本的安裝步驟:

一、添加composer依賴關係

在symfony裡,用composer來管理依賴關係

1.找到Bundle的包的名稱

在包的README裡一般都告訴了我們它的名稱,如果沒有,可以在https://packagist.org網站裡搜尋到

2.通過composer來安裝Bundle

知道了bundle的包名之後,我們可以通過composer來安裝它

$ composer require codeguy/upload

codeguy/upload是一個上傳檔案的bundle,在上一章《Symfony2使用第三方庫Upload製作圖片上傳執行個體詳解》中我們使用到。

執行上面的指令,composer會給你的項目選擇一個最好版本的bundle,把它添加到composer.json中,並將bundle下載到vendor/目錄下。如果你想要下載一個指定的版本,在bundle的包名後增加:版本號碼

二、註冊Bundle

現在,第三方的bundle已經安裝到你的symfony項目中了,在vendor/目錄下。此時我們需要在app/AppKernel.php裡註冊安裝好的bundle

例如DoctrineFixturesBundle:

class AppKernel extends Kernel{  public function registerBundles()  {    $bundles = array(      //...在這裡註冊      new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),    );  }  //...}

三、配置Bundle

有的包需要一些額外的配置在 app/config/config.yml檔案裡。包的文檔會告訴我們關於怎樣配置,也可以通過指令來參考包的配置

$ app/console config:dump-reference

例如TwigBundle:

$ app/console config:dump-reference TwigBundle

會得到如下的提示

# Default configuration for "TwigBundle"twig:  exception_controller: 'twig.controller.exception:showAction'  # Deprecated since 2.6, to be removed in 3.0. Use twig.form_themes instead  form:    resources:      # Default:      - form_div_layout.html.twig      # Example:      - MyBundle::form.html.twig  form_themes:    # Default:    - form_div_layout.html.twig     # Example:    - MyBundle::form.html.twig  globals:    # Examples:    foo:         "@bar"    pi:         3.14    # Prototype    key:      id:          ~      type:         ~      value:        ~  autoescape:    # Defaults:    - Symfony\Bundle\TwigBundle\TwigDefaultEscapingStrategy    - guess  autoescape_service:  null  autoescape_service_method: null  base_template_class: ~ # Example: Twig_Template  cache:        '%kernel.cache_dir%/twig'  charset:       '%kernel.charset%'  debug:        '%kernel.debug%'  strict_variables:   ~  auto_reload:     ~  optimizations:    ~  paths:    # Prototype    paths:        ~

具體的第三方bundle安裝方法,和該bundle的使用方法都可以在它的README檔案裡查看。

本文永久地址:http://blog.it985.com/7059.html
本文出自 IT985部落格 ,轉載時請註明出處及相應連結。

更多關於PHP架構相關內容感興趣的讀者可查看本站專題:《php優秀開發架構總結》,《codeigniter入門教程》,《CI(CodeIgniter)架構進階教程》,《Yii架構入門及常用技巧總結》及《ThinkPHP入門教程》

希望本文所述對大家基於Symfony架構的PHP程式設計有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.