2016-05-10 2 views
0

では見られない、私はGuzzleHttpクライアントクラスSymfony2の

http://docs.guzzlephp.org/en/5.3/quickstart.html

からGuzzleHttpにロードされていると私は、このアクションを呼び出すとき

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"? 

なぜでしょうか?

おかげ

+0

アプリケーションにどのようにインストールしましたか? – zerkms

+0

私は "guzzlehttp/guzzle"を "require"しています: "^ 3.8"とそれをベンダーフォルダに更新しました – CarlRyds

+1

古いバージョンのguzzleがインストールされている可能性があります。私は "guzzlehttp/guzzle"を持っています: "^ 6.2"ベンダーの下のClientクラスをチェックして名前空間を確認してください。これは以前のバージョンとは異なります。 \ Guzzleを使うことについてのコメントは無視してください...先行するバックスラッシュは必要ありません。そして、はい、グレッグ3.xは非常に古いです。それを使用する必要がある場合は、適切な文書に従ってください。 – Cerad

答えて

2

あなたが見ているドキュメントよりも、インストールがつがつ食うの異なるバージョンを持っているように見えます。あなたが使用した文を次のように変更すると、エラーメッセージが表示されます。

use Guzzle\Http\Client; 

これは動作するはずです。

関連する問題