Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

php - How to autoload Guzzle in Laravel 4?

How can I autoload Guzzle in Laravel 4?

I am encountering the following error when I try to create a new GuzzleHttp/Client:

Symfony  Component  Debug  Exception  FatalErrorException
Class 'GuzzleHttpClient' not found

I have the following set up in my composer.json autoload section:

autoload: {
    "psr-0": {
        "Guzzle": "src/"
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't need to add Guzzle to your composer.json, it's already autoloaded by it's own composer.json.

Guzzle 4

PHP 5.4.x+ required

composer require "guzzlehttp/guzzle" "~4.0"

Create a client:

$client = new GuzzleHttpClient();

Get results:

$response = $client->get('http://api.github.com/users/antonioribeiro');

dd($response->getBody());

Guzzle 3

Install it:

composer require "guzzle/guzzle" "~3.0"

Create a client setting the base URL:

$client = new GuzzleServiceClient('http://api.github.com/users/');

Get your response:

$username = 'antonioribeiro';

$response = $client->get("users/$username")->send();

And display it:

dd($response);

If you still don't get it running, check the file vendor/composer/autoload_psr4.php, Guzzle must appear in it. If it doesn't, remove your vendor folder and install it again:

rm -rf vendor
rm composer.lock
composer install

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...