2014-01-24 110 views
1

試圖在Yii Framework中獲取新的Amazon SDK http://docs.aws.amazon.com/aws-sdk-php/guide/latest/quick-start.htmlYii框架中的Amazon SDK

亞馬遜醫生說用這樣的:

// Include the SDK using the Composer autoloader 
require 'vendor/autoload.php'; 

use Aws\S3\S3Client; 

// Instantiate the S3 client with your AWS credentials 
$s3Client = S3Client::factory(array(
    'key' => 'YOUR_AWS_ACCESS_KEY_ID', 
    'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', 
)); 

但是你不能在Yii的控制器的方法使用「使用」,所以在Yii中,你可以使用setPathOfAlias使用的命名空間。

我想這一點:

  Yii::import('application.vendors.amazon-sdk.*'); 
      Yii::setPathOfAlias('AwsSDK',Yii::getPathOfAlias('application.vendors.amazon-sdk.*')); 
      require 'aws-autoloader.php'; 

      // Instantiate the S3 client with your AWS credentials 
      $aws = AwsSDK\Aws\Common\Aws::factory(array(
       'key' => '************', 
       'secret' => '************', 
      )); 

它加載 「Aws.php」 正確,但它說: 「致命錯誤:類 'AwsSDK \ AWS \ COMMON \ AWS' 未找到」

問題是什麼?

謝謝

回答

0

這是爲Yii 1. *?

在這種情況下,只檢查我的配置是: https://github.com/IvoRe/ES32

但你不能用‘’Yii中在控制器的方法」使用

你不是在班級頂部使用「使用」?因此,使用聲明將出現在Controller聲明之前。從this tutorial

報價:

Aliasing or importing should occur in the highest scope of a namespace or in the global scope. Trying to do this in the scope of a method or function is invalid syntax.

+0

我不想把「使用」的文件的開頭,我需要把方法。 – FlamingMoe

+0

我不相信這是可能的。 「使用」必須始終出現在班級定義之前。這是解析器的一條指令。 –