iTh*_*ink 2 php amazon namespaces amazon-s3 yii
这是我的代码:
public function actionS3()
{
require_once(Yii::app()->basePath . '/extensions/s3/aws.phar');
use Aws\S3\S3Client;
}
Run Code Online (Sandbox Code Playgroud)
它给了我错误
解析错误:语法错误,意外'使用'(T_USE)...
因为您应该在命名空间之后在文件顶部编写use
use Aws\S3\S3Client;
class Foo
{
public function actionS3()
{
require_once(Yii::app()->basePath . '/extensions/s3/aws.phar');
}
}
Run Code Online (Sandbox Code Playgroud)
但是在Yii 1中它可能没有帮助.使用此方法处理具有命名空间的第三方组件:
Yii::setPathOfAlias('Aws', Yii::getPathOfAlias('common.vendors.Aws'));
$model = new Aws\S3\S3Client();
Run Code Online (Sandbox Code Playgroud)
最后,如果您要使用phar存档,可以将其包含在php.ini中:
auto_prepend_file="/custom/path/unleashapi/protected/extensions/goutte.phar"
Run Code Online (Sandbox Code Playgroud)