Use composer to install dependencies in CodeIgniter

Basic Information

  • CodeIgniter version: 3.1.8
  • Nginx : Tengine / 2.1.2 (nginx / 1.6.2)
  • MySQL: Ver 14.14 Distrib 5.6.33, for Linux (x86_64) using EditLine wrapper
  • PHP: 5.6.30
  • Zend Engine : v2.6.0
  • CentOS release 6.8 (Final)

Composer installation

  • Refer to Composer installation

Use with CodeIgniter

  • Step 1: composer require php-curl-class/php-curl-class in CMD
  • Step 2: Introduce the autoload file

application/libraries/MY_Composer.php

class MY_Composer
{
    function __construct()
    {
        include("./vendor/autoload.php");
    }
}
  • Step 3: Configure the load file

application/config/autoload.php

$autoload['libraries'] = array('MY_Composer','database','session');
  • Step 4: Introduce and write code in the controller

application/controllers/Test.php

defined('BASEPATH') OR exit('No direct script access allowed');

use \Firebase\JWT\JWT;
use \Curl\Curl;

class Test extends CI_Controller {
    public function index()
	{
        $curl = new Curl();
		$curl->get('http://www.baidu.com/');

		if ($curl->error) {
		    echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage . "\n";
		} else {
		    echo 'Response:' . "\n";
		    var_dump($curl->response);
		}
	}
}
  • Step 5: Finish

Packagist dependencies

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325094030&siteId=291194637
Recommended