【问题标题】:Using "Use" keyword in yii php在 yii php 中使用“使用”关键字
【发布时间】:2014-04-30 11:45:15
【问题描述】:

这是我的代码:

public function actionS3()
{
  require_once(Yii::app()->basePath . '/extensions/s3/aws.phar');
   use Aws\S3\S3Client;
}

它给了我错误

解析错误:语法错误,在...中出现意外的“使用”(T_USE)

【问题讨论】:

标签: php amazon-s3 yii namespaces amazon


【解决方案1】:

因为你应该在命名空间之后的文件顶部写 use

use Aws\S3\S3Client;

class Foo
{
    public function actionS3()
    {
        require_once(Yii::app()->basePath . '/extensions/s3/aws.phar');
    }
}

但在 Yii 1 中它可能无济于事。使用此方法处理具有命名空间的第三方组件:

Yii::setPathOfAlias('Aws', Yii::getPathOfAlias('common.vendors.Aws'));
$model = new Aws\S3\S3Client();

最后,如果你要使用 phar 归档,你可以将它包含在 php.ini 中:

auto_prepend_file="/custom/path/unleashapi/protected/extensions/goutte.phar"

【讨论】:

  • 谢谢。事实上,第一个解决方案有所帮助。
猜你喜欢
  • 2017-11-25
  • 1970-01-01
  • 2013-11-09
  • 1970-01-01
  • 1970-01-01
  • 2011-09-13
  • 2013-11-01
  • 2013-01-29
  • 2017-05-27
相关资源
最近更新 更多