如何自动加载Guzzle在Laravel 4? [英] How to autoload Guzzle in Laravel 4?
问题描述
如何自动加载Laravel 4中的 Guzzle ?
我在尝试创建新的GuzzleHttp / Client时遇到以下错误:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
未找到类'GuzzleHttp \Client'
以下设置在我的composer.json自动加载部分:
autoload:{
psr-0:{
Guzzle \\:src /
}
}
Guzzle 4
PHP 5.4.x +必需
composer requireguzzlehttp / guzzle〜4.0
创建客户端:
$ client = new \GuzzleHttp\Client();
取得结果:
$ response = $ client-> get('http://api.github.com/users/antonioribeiro');
dd($ response-> getBody());
Guzzle 3
安装: / p>
composer requireguzzle / guzzle〜3.0
创建一个客户端设置基本URL:
$ client = new \\ \\Guzzle\Service\Client('http://api.github.com/users/');
取得回应:
$ username ='antonioribeiro';
$ response = $ client-> get(users / $ username) - > send()
并显示:
dd($ response);
如果仍然无法运行,请检查文件 composer / autoload_psr4.php
,Guzzle必须出现在其中。如果没有,请删除您的供应商文件夹并再次安装:
rm -rf vendor
rm composer。 lock
composer install
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 'GuzzleHttp\Client' not found
I have the following set up in my composer.json autoload section:
autoload: {
"psr-0": {
"Guzzle\\": "src/"
}
}
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 \GuzzleHttp\Client();
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 \Guzzle\Service\Client('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
这篇关于如何自动加载Guzzle在Laravel 4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!