找不到类'GuzzleHttp\Client'
问题描述:
我第一次同时使用 Guzzle 和Codeigniter 3.0。我也承认我是第一次使用php名称空间。
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.
我试图根据文档中提供的示例使用Guzzle提出一个非常简单的get请求。 (Guzzle的文档对codeigniter没说什么。)
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).
Guzzle文件位于application / class / guzzle
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;
}
这是我的简单观点
<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>
这是我遇到的错误
遇到PHP错误
严重性:错误
消息:未找到类'GuzzleHttp\Client'
文件名:controllers / hello.php
行号:22
回溯:
答
在 application / config / config.php
$config['composer_autoload'] = FCPATH.'vendor/autoload.php';
对我来说很好