dongmu4591 2014-03-29 00:04
浏览 40
已采纳

如何在Laravel 4中自动加载Guzzle?

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/"
    }
}
  • 写回答

1条回答 默认 最新

  • dpbv85276 2014-03-29 00:40
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下