如何加载AWS SDK到CakePHP的?

编程入门 行业动态 更新时间:2024-10-09 23:15:03
本文介绍了如何加载AWS SDK到CakePHP的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建一个S3插件我的应用程序。在应用程序/插件/ S3 /控制器/组件/ S3Component.php 我有这些:

< PHP 应用::进口(供应商,AWS / AWS-自动加载机); 使用AWS \ S3 \ S3Client; 类S3Component扩展组件{     公共职能loadS3(){         $ S3 = S3Client ::工厂(阵列(             '键'=> '',             秘密=> ''         ));         返回$ S3;     } }

在我的应用程序的控制,我把它用 $ S3 = $这个 - > S3-> loadS3();

这引发错误错误:类'AWS \ S3 \ S3Client'未找到

我尝试添加该行:应用::使用(供应商,AWS / AWS / S3 / S3Client'); 的组件类,并删除使用AWS \ S3 \ S3Client; 。它显示了错误:类'S3Client'未找到

在AWS SDK中的文件夹应用程序/插件/ S3 /供应商/ AWS

我加载了S3对象参考:的docs.aws.amazon/aws-sdk-php/guide/latest/quick-start.html#factory-method

解决方法:

这是我的组件现在看起来像@akirk的帮助。

< PHP ini_set('include_path中,ROOT DS'库'PATH_SEPARATOR ini_get('include_path中)PATH_SEPARATOR ROOT .DS应用程序/插件/ S3 /供应商/ AWS。。。。。); 需要ROOT。 DS。 应用程序/插件/ S3 /供应商/ AWS / AWS-autoloader.php; 使用AWS \ S3 \ S3Client; 类S3Component扩展组件{     公共职能loadS3(){         $ S3 = S3Client ::工厂(阵列(             '键'=> '',             秘密=> ''         ));         返回$ S3;     } }

解决方案

显然,AUTOIMPORT不起作用。你应该这样做在本教程中,使用要求

要求供应商/ autoload.php;

作为自动加载机制不应被CakePHP的感动。

I'm creating a S3 plugin for my app. In app/Plugin/S3/Controller/Component/S3Component.php I have these:

<?php App::import('Vendor', 'aws/aws-autoloader'); use Aws\S3\S3Client; class S3Component extends Component { public function loadS3 () { $s3 = S3Client::factory(array( 'key' => '', 'secret' => '' )); return $s3; } }

In my app's controller, I call it using $s3 = $this->S3->loadS3();

It throws the error Error: Class 'Aws\S3\S3Client' not found

I tried adding the line: App::uses('Vendor', 'aws/Aws/S3/S3Client'); to the component class, and removed use Aws\S3\S3Client;. It shows Error: Class 'S3Client' not found

The AWS SDK in in the folder app/Plugin/S3/Vendor/aws

I'm loading the S3 object with reference to: docs.aws.amazon/aws-sdk-php/guide/latest/quick-start.html#factory-method

Solution:

This is how my component looks like now with the help of @akirk.

<?php ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'). PATH_SEPARATOR . ROOT .DS . 'app/Plugin/S3/Vendor/aws'); require ROOT . DS . 'app/Plugin/S3/Vendor/aws/aws-autoloader.php'; use Aws\S3\S3Client; class S3Component extends Component { public function loadS3 () { $s3 = S3Client::factory(array( 'key' => '', 'secret' => '' )); return $s3; } }

解决方案

Clearly the autoimport doesn't work. You should do it as in the tutorial, use require

require 'vendor/autoload.php';

as the autoloading mechanism shouldn't be touched by CakePHP.

更多推荐

如何加载AWS SDK到CakePHP的?

本文发布于:2023-11-28 14:26:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642788.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   AWS   CakePHP   SDK

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!