【发布时间】:2023-09-04 10:01:01
【问题描述】:
我已经从
加载了 GuzzleHttphttp://docs.guzzlephp.org/en/5.3/quickstart.html
并拥有
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"?
有什么想法吗?
谢谢
【问题讨论】:
-
你是如何在你的应用程序中安装它的?
-
是的,在 composer.json 我有 "require" "guzzlehttp/guzzle": "^3.8" 并且已经更新了它和它在供应商文件夹中
-
我认为您可能安装了旧版本的 guzzle。我有 "guzzlehttp/guzzle": "^6.2" 也许检查供应商下的客户端类以查看它的名称空间。在早期版本中有所不同。并无视关于使用 \Guzzle 的评论......根本不需要前导反斜杠。是的,guzzle 3.x 已经很老了。如果您确实需要使用它,请遵循相应的文档。