类'Aws \ Common \ Aws'找不到cakephp

时间:2015-08-17 14:18:27

标签: php cakephp amazon-web-services amazon-s3 amazon-ec2

我在我的cakephp中使用AWS PHP SDK V2.8。我正在使用AWS ec2 ubuntu机器。

  

我使用的是zip文件而不是任何作曲家。

我收到了以下错误。

Class 'Aws\Common\Aws' not found 

我创建了一个自定义组件,用于访问SDK的所有功能。引用https://github.com/Ali1/cakephp-amazon-aws-sdk

我的文件夹结构如下

enter image description here

这是我的AmazonComponent.php

<?php

App::uses('Component', 'Controller');
use Aws\Common\Aws;

/**
 * AmazonComponent
 *
 * Provides an entry point into the Amazon SDK.
 */
class AmazonComponent extends Component {

  /**
   * Constructor
   * saves the controller reference for later use
   * @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components
   * @param array $settings Array of configuration settings.
   */
  public function __construct(ComponentCollection $collection, $settings = array()) {
    $this->_controller = $collection->getController();
    parent::__construct($collection, $settings);
  }

  /**
   * Initialization method. Triggered before the controller's `beforeFilfer`
   * method but after the model instantiation.
   *
   * @param Controller $controller
   * @param array $settings
   * @return null
   * @access public
   */
  public function initialize(Controller $controller) {
    // Handle loading our library firstly...
      $this->Aws = Aws::factory(Configure::read('Amazonsdk.credentials'));
  }

  /**
   * PHP magic method for satisfying requests for undefined variables. We
   * will attempt to determine the service that the user is requesting and
   * start it up for them.
   *
   * @var string $variable
   * @return mixed
   * @access public
   */
  public function __get($variable) {
    $this->$variable = $this->Aws->get($variable);
    return $this->$variable;
  }
}

我在文件的顶部添加了这两行,并引用了这个问题 How to load AWS SDK into CakePHP?

ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'). PATH_SEPARATOR . ROOT .DS . 'app/Plugin/Amazonsdk/Vendor/aws');

require ROOT . DS . 'app/Plugin/Amazonsdk/Vendor/aws/aws-autoloader.php';

我错了,我该如何解决?

1 个答案:

答案 0 :(得分:0)

@urfusion你可以将AWS SDK文件夹从app/Plugin移到app/Vendor In Side app / Vendor然后尝试导入具有Function AmazonComponent的aws-sdk initialize

我正在使用AWS PHP SDK V3

//首先处理我们的库...

 App::import('Vendor','aws-autoloader',array('file'=>'aws'.DS.'aws-autoloader.php'));