天天看點

FOSRestBundle功能包:安裝功能包

  • 原文出處:1-setting_up_the_bundle.md
  • 原文作者:FriendsOfSymfony
  • 授權許可:創作共用協定
  • 翻譯人員:FireHare
  • 校對人員:
  • 适用版本:FOSRestBundle 0.12.0
  • 文章狀态:草譯階段

Step 1: Setting up the bundle

A) Download FOSRestBundle(下載下傳FOSRestBundle)

Note:

注意:

This bundle recommends using JMSSerializer which is integrated into Symfony2 via JMSSerializerBundle.Please follow the instructions of the bundle to add it to your composer.json and how to set it up.If you do not add a dependency to JMSSerializerBundle, you will need to manually setup an alternativeservice and configure the Bundle to use it via the

service

section in the app config

本功能包建議使用 通過 JMSSerializerBundle 內建到Symfony2中的 JMSSerializer,請遵循功能包中的訓示将其添加到您的 composer.json 中并設定它。如果您沒有添加JMSSerializerBundle的依賴,您将需要手工安裝并配置該功能包,以便在應用配置中通過service段來使用它。

Ultimately, the FOSRestBundle files should be downloaded to the

vendor/bundles/FOS/RestBundle

directory.

最終FOSRestBundle檔案将被下載下傳到 vendor/bundles/FOS/RestBundle 目錄中。

This can be done in several ways, depending on your preference. The firstmethod is the standard Symfony2 method.

根據您的喜好,這可以通過多種方式來實作。第一種方式是标準的Symfony2方式:

Using the vendors script(使用vendors腳本)

Add the following lines in your

deps

file:

在您的deps檔案中添加下列語句:

[FOSRest]
    git=git://github.com/FriendsOfSymfony/FOSRest.git
    target=fos/FOS/Rest
[FOSRestBundle]
    git=git://github.com/FriendsOfSymfony/FOSRestBundle.git
    target=bundles/FOS/RestBundle      

Now, run the vendors script to download the bundle:

現在,運作vendors腳本來下載下傳該功能包:

$ php bin/vendors install      

Using submodules(使用子子產品)

If you prefer instead to use git submodules, then run the following:

如果您喜歡使用git子子產品來代替,您可以使用下列語句:

$ git submodule add git://github.com/FriendsOfSymfony/FOSRestBundle.git vendor/bundles/FOS/RestBundle
$ git submodule add git://github.com/FriendsOfSymfony/FOSRest.git vendor/fos/FOS/Rest
$ git submodule update --init      

Using composer(使用composer)

Simply run assuming you have installed composer.phar or composer binary:

假設您已經安裝了composer.phar 或 composer 指令,您隻需要簡單運作以下指令:

$ composer require friendsofsymfony/rest-bundle      

B) Configure the Autoloader (not needed for composer)(配置Autoloader,composer不需要)

Add the

FOS

namespace to your autoloader:

在您的autoloader中添加FOS全稱空間:

<?php
// app/autoload.php
$loader->registerNamespaces(array(
    // ...
    'FOS\\Rest' => __DIR__.'/../vendor/fos',
    'FOS'       => __DIR__.'/../vendor/bundles',
));      

C) Enable the bundle(啟動功能包)

Finally, enable the bundle in the kernel:

最後,在kernel中啟動功能包:

<?php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\RestBundle\FOSRestBundle(),
        // if you installed FOSRestBundle using composer you shoudn't forget
        // also registering JMSSerializerBundle.
        // new JMS\SerializerBundle\JMSSerializerBundle(),
    );
}      

That was it!(就是這樣)

上一篇: Oracle資料庫
下一篇: Oracle資料庫