[Solved] Implement Mpdf |
Hello friends!
I'm trying to implement the mpdf library in CodeIgniter 4 like this: Accessing App/Config/Constants.php includes the line of code: Code: defined('MPDF') || define('MPDF', ROOTPATH . 'vendor/autoload.php'); In the App/Config/Autoload.php file, I added one more element to the psr4 array: Code: $psr4 = [ In the App/Libraries file, I created a class to instantiate Mpdf: Code: <?php namespace App\Libraries; In the Controller, I'm calling the Mpdf class like this: Code: use App\Libraries\Mpdf; But the displayed page is corrupted, as seen in the link below. Image corrupt My question is: what is the correct way to implement Mpdf in CodeIgniter 4? Note: I included Mpdf to the project via Codeigniter composer Thanks in advance!
You don't need to do any of that. Composer are automatically loaded if you have it installed in; ROOTPATH.'vendor/autoload.php'.
So skip the whole Config and library thing and just use this in the controller. What you are doing above only needs to be done if you are loading an third party script without support for composer (or don't want it). PHP Code: use \Mpdf\Mpdf; If you want to load a psr4 compatible library without Composer, you do it like this. (Don't know if it works for Mpdf). PHP Code: $psr4 = [ (01-26-2020, 12:48 AM)jreklund Wrote: You don't need to do any of that. Composer are automatically loaded if you have it installed in; ROOTPATH.'vendor/autoload.php'. jreklund thank you for your help! I followed what you guided and it worked! In the controller the code for Mpdf looked like this: PHP Code: use \Mpdf\Mpdf; |
Welcome Guest, Not a member yet? Register Sign In |