Class 'GuzzleHttp\Client' not found

user2115154 picture user2115154 · Mar 31, 2015 · Viewed 16.6k times · Source

I am using BOTH Guzzle and Codeigniter 3.0 for the first time. Also I admit I am using php namespace for the first time.

I am trying to make a very simple get request using Guzzle according to the examples provided in the docs. (The Guzzle docs say nothing about codeigniter).

The Guzzle files are located at application/class/guzzle

Here is my very simple controller

public function indey () {

        $data = array();
        $data['main_content'] = "hiview";
        $data['title'] = "Data Analyzer - Welcome";
        $data['xas'] = $this->guzzler();
        $this->load->view('template', $data);
    }

    private function guzzler() {
        $client = new GuzzleHttp\Client;
        $response = $client->get('http://guzzlephp.org');
        return $response;
    }

This is my simple view

    <div class="row">
        <div class="col-xs-12">
             <h1>Hi</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <h1><?php var_dump($xas); ?></h1>
        </div>
    </div>

This is the error I am getting

A PHP Error was encountered Severity: Error Message: Class 'GuzzleHttp\Client' not found Filename: controllers/hello.php Line Number: 22 Backtrace:

Answer

aitbella picture aitbella · Dec 25, 2016

In application/config/config.php

$config['composer_autoload'] = FCPATH.'vendor/autoload.php';

it work fine for me