Wednesday, 15 April 2015

PHP Requests Library within Codeigniter -



PHP Requests Library within Codeigniter -

i'm using requests library (http://requests.ryanmccue.info/) php.

i installed composer , added next json configuration in composer.json:

{ "require": { "rmccue/requests": ">=1.0" }, "autoload": { "psr-0":{"requests" : "library/"} } }

so in controller i'm trying run request through library , get:

public function index() { requests::register_autoloader(); $headers = array('accept' => 'application/json'); $options = array('auth' => array('user', 'pass')); $request = requests::get('https://api.github.com/gists', $headers, $options); var_dump($request->status_code); // int(200) var_dump($request->headers['content-type']); // string(31) "application/json; charset=utf-8" var_dump($request->body); }

: class 'requests' not found in ../application/controllers/test.php on line 34

you shouldn't need add together autoload block composer.json, including library in require block utilize autoload configuration provided package.

you utilize autoload block configure loading of code not installed via composer package.

you need require composer autoload file, if haven't

require 'vendor/autoload.php';

somewhere run before code needs composer libraries (generally it's in "bootstrap" process)

and, need run composer install install configured dependencies.

php codeigniter

No comments:

Post a Comment