Search code examples
phpcodeignitercomposer-phpcodeigniter-3autoloader

How to troubleshoot Composer autoload in Codeigniter?


I am new to using Composer in Codeigniter and have read all I can to try and fix my issue, but are coming up short. The autoloader seems to to be autoloading? So here is where I am stuck:

  • I have installed a composer.
  • Required the MPDF package using composer require pdf/mpdf
  • I did that from the root of my project, so the vendor folder, as well as the composer.json file is on the root of my project
  • In my config/config.php file, I changed the composer_autoload value to $config['composer_autoload'] = FCPATH . "/vendor/autoload.php";

Then I created a simple function in my default controller like this:

function m_pdf() {
        $mpdf = new mPDF();
        $mpdf->WriteHTML('Hello World');
        $mpdf->Output();
    }

But when I run it, I get an error: Message: Class 'mPDF' not found

I have tried moving everything to the application folder, and change the value in the config file to TRUE, I have tried calling the autoloader from the function itself, but no luck.

I feel I am missing something obvious. Maybe some dependencies. As I said, I am new to use the composer. There were some suggestions on the web about running php composer.phar but I get an error when I try and run that. Could that be it?


Solution

  • 1) in namespace => use correct Mpdf class

    If still not help => composer dump-autoload(reconfigure your composer classMap)

    If dump-autoload not help =>

    • remove vendor directory
    • composer install