【问题标题】:Class 'Aws\Common\Aws' not found cakephp找不到类 'Aws\Common\Aws' cakephp
【发布时间】:2015-11-10 05:32:25
【问题描述】:

我在我的 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

我的文件夹结构如下

这是我的 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';

我哪里错了,我该如何解决?

【问题讨论】:

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


    【解决方案1】:

    @urfusion 您能否将 AWS SDK 文件夹从 app/Plugin 移动到 app/Vendor 在应用程序/供应商旁边,然后尝试导入具有功能 initialize 的 aws-sdk AmazonComponent

    我正在使用 AWS PHP SDK V3

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 2020-08-05
      • 2019-04-06
      • 1970-01-01
      • 2020-08-17
      • 2012-11-01
      相关资源
      最近更新 更多