在symfony2中找不到GuzzleHttp客户端类
我已从中加载GuzzleHttp 还有在symfony2中找不到GuzzleHttp客户端类,symfony,http,guzzle,Symfony,Http,Guzzle,我已从中加载GuzzleHttp 还有 use GuzzleHttp\Client; 当我称之为行动 public function googlevolumeAction(Request $request) { $data = $request->request->all(); $searchStr = $data['search']; $client = new Client(); $req = $client->requ
use GuzzleHttp\Client;
当我称之为行动
public function googlevolumeAction(Request $request)
{
$data = $request->request->all();
$searchStr = $data['search'];
$client = new Client();
$req = $client->request('GET', 'https://www.googleapis.com/books/v1/volumes?q=intitle:' .$searchStr, []);
$decode = json_decode($req->getBody());
$total = $decode->totalItems;
$search = null;
if ($total != 0) {
$search = $decode->items;
}
return $this->render('BloggerBlogBundle:Page:googlevolume.html.twig',
['items' => $search]);
}
我得到这个错误
Attempted to load class "Client" from namespace "GuzzleHttp".
Did you forget a "use" statement for e.g. "Guzzle\Http\Client",
"Guzzle\Service\Client", "Symfony\Component\BrowserKit\Client",
"Symfony\Component\HttpKernel\Client" or
"Symfony\Bundle\FrameworkBundle\Client"?
你知道为什么吗
谢谢看起来您安装的guzzle版本与您正在查看的文档不同。从您收到的错误消息来看,如果您将use语句更改为:
use Guzzle\Http\Client;
它应该可以工作。看起来您安装的guzzle版本与您正在查看的文档不同。从您收到的错误消息来看,如果您将use语句更改为:
use Guzzle\Http\Client;
它应该可以工作。您是如何在应用程序中安装它的?是的,在composer.json中,我有“require”“guzzlehttp/guzzle”:“^3.8”,并在供应商文件夹中更新了它和它。我想您可能安装了一个旧版本的guzzle。我有“guzzlehttp/guzzle”:“^6.2”可能会检查vendor下的客户机类以查看其名称空间。这在早期版本中是不同的。并忽略有关使用\Guzzle。。。根本不需要前导反斜杠。是的,guzzle 3.x已经很老了。如果您确实需要使用它,请遵循相应的文档。您是如何在应用程序中安装它的?是的,在composer.json中,我有“require”“guzzlehttp/guzzle”:“^3.8”,并已在供应商文件夹中更新了它和它。我想您可能安装了一个较旧版本的guzzle。我有“guzzlehttp/guzzle”:“^6.2”可能会检查vendor下的客户机类以查看其名称空间。这在早期版本中是不同的。并忽略有关使用\Guzzle。。。根本不需要前导反斜杠。是的,guzzle 3.x已经很老了。如果您确实需要使用它,请遵循相应的文档。