Yii2 Composer Library未在Component中加载

时间:2014-06-10 22:26:42

标签: php yii composer-php yii2

我正在使用我通过Composer安装的Google PHP库。

  

" google / apiclient":" *"

我可以在视图中运行测试代码但是当我尝试在Controller中运行它时会出现错误。

  

Class' backend \ controllers \ Google_Client'找不到

这是测试代码

$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("***********************");
$service = new Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);

2 个答案:

答案 0 :(得分:1)

Class 'backend\controllers\Google_Client' not found

您似乎没有使用。

定义命名空间
use Google\Google_Client; //or somethong like this

如果Google_Client没有名称空间使用require从文件中导入类

require \Yii::getAlias('common/components/simple_html_dom') . '.php';

答案 1 :(得分:0)

我认为Google_Client不使用命名空间。所以使用" \"。

$ client = new \ Google_Client();