Preface, I hope codeigniter4 will be released earlier. At present, there are codeigniter3 for the project, and I want to use so many excellent third-party libraries on github. What did I do? And these libraries are basically installed through composer. Here’s how to integrate composer package manager:

1. Install composer, which is not to be overlooked.

2. Create a new composer. JSON file in the project root directory, such as a JWT Library in my current Ci

  "require": {
    "firebase/php-jwt": "*"

3. Command line execution under this directory: composer install
Or the above two steps can be simplified to the following steps
composer require firebase/php-jwt

4. There are two ways to formally integrate into ci:

Method 1: Simple and crude (not recommended)

require_once './vendor/autoload.php';
// The above line is added to this location in index. PHP
require_once BASEPATH.'core/CodeIgniter.php';

Method 2: Elegant (recommended)
New MY_Composer.php for application/libraries

 * Notes on MY_Composer
 * @author new pig
class MY_Composer 
    function __construct() 

Then modify it in config/autoload.php

$autoload['libraries'] = array('MY_Composer','database','session');

5, use

use \Firebase\JWT\JWT;

class TestController extends CI_Controller {
    public function index() {
        $key = "example_key";
        $token = array(
            "iss" => "",
            "aud" => "",
            "iat" => 1356999524,
            "nbf" => 1357000000
        $jwt = JWT::encode($token, $key);
        $decoded = JWT::decode($jwt, $key, array('HS256'));


After that, I hope it will be helpful to you all.