Class not found when using external library

818 Views Asked by At

I just deployed a fresh version of CI4 and I'm trying to get used to the new features and changes.

I took some legacy code from a CI3 based application and started to upgrade it.

This legacy code uses the Elastica library (to interact with Elasticsearch), so I downloaded the latest Elastica release (https://github.com/ruflin/Elastica), unziped the "src" directory in app/Libraries/Elastica and tried to use it in a controller.

I can't use Composer to deploy the library for obscure security reasons.

Here is how my controller looks :

<?php

namespace App\Controllers;

use App\Libraries\Elastica;

class MyController extends BaseController
{
    public function __construct()
    {
      // Create a new Elastica instance
      $this->elastica = new Elastica\Client();
    }
    
    public function index()
    {
      $foobar = $this->elastica->getIndex('foobar');
      
      var_dump($foobar);
    }
}

But I keep having this error :

[Error]

Class "App\Libraries\Elastica\Client" not found

at APPPATH/Controllers/MyController.php:12

I have the feeling that I did everything by the book but I am obviously missing something ><

If you could help me finding where I made a mistake, I would really appreciate it.

0

There are 0 best solutions below