在symfony2中找不到GuzzleHttp客户端类

时间:2016-05-10 22:48:35

标签: symfony http guzzle

我已经从

加载了GuzzleHttp

http://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"?

任何想法为什么?

感谢

1 个答案:

答案 0 :(得分:2)

看起来您安装的guzzle版本与您正在查看的文档不同。从您收到的错误消息来看,如果您将use语句更改为:

use Guzzle\Http\Client;

它应该有用。