-1

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?

Mujahid Bhoraniya
  • 1,518
  • 10
  • 22
  • 1
    If you check the [documentation for mpdf](https://mpdf.github.io/installation-setup/installation-v7-x.html), their example is: `$mpdf = new \Mpdf\Mpdf();`. You need to use the correct namespace and the correct casing. – M. Eriksson Feb 25 '20 at 06:46
  • Thank you @MagnusEriksson. I have corrected that mistake but continue to have the same problem: ``Message: Class 'Mpdf\Mpdf' not found`` – Johan Havenga Feb 25 '20 at 09:38
  • Are you sure the path is correct? What do you get if you do: `var_dump(is_file(FCPATH . "/vendor/autoload.php"));`? – M. Eriksson Feb 25 '20 at 12:27
  • YAY, got it sorted. Seems some form of caching was in play, so after all the changes, and a new browser window, and a few Ctrl+F5s it is finally working. Thank you for your patience! – Johan Havenga Feb 25 '20 at 12:38

1 Answers1

0

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
  • Thank you for the suggestions above. I added the correct namespace in the function ``$mpdf = new \Mpdf\Mpdf()`` and tried dumping the autoload and deleted the vendor folder, and installed composer again pulling in all the files, but when I run the function I get: **Message: Class 'Mpdf\Mpdf' not found** – Johan Havenga Feb 25 '20 at 09:32