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

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

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

I use zip files not any composer.

我遇到以下错误。

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';

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

最佳答案

@urfusion 你能不能把 AWS SDK 文件夹从 app/Plugin 移到 app/Vendor 在 app/Vendor 里面 然后尝试导入 aws-sdk AmazonComponent 具有函数 initialize

我正在使用 AWS PHP SDK V3

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

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

关于php - 找不到类 'Aws\Common\Aws' cakephp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32052772/

相关文章:

php - 5 .htaccess 重写 : Force HTTPS, 删除 index.php,删除 .php,强制 www,强制尾部斜线

php - PHP 中单引号和双引号字符串有什么区别?

apache - 运行 Tomcat 没有响应 : does not start, 什么都不做

python - 如何将内存值中的字典数据直接写入s3存储桶(如csv文件),而无需写入文件然后上传

php - 在模板的 Symfony 翻译中使用 Twig 变量

php - 需要在基于 php 的 CMS 中添加下一篇文章导航器

php - 如何在直接付款之前保存参数并使用 Paypal 直接付款相应地更新表格?

model-view-controller - CakePHP 对一起使用 set() 和 compact() 的说明。仅适用于 compact()

php - CakePHP:将日期验证为 'dmy',但将其保存到MySQL作为正确的日期

amazon-web-services - 我们项目的新基础设施(AWS、GCP)