First, note that the configuration item $config['composer_autoload']
setado to TRUE
will only upload libraries within application/vendor
. That implies, at the very least, that there is a composer.json
inside the application folder. If you installed the mPDF
Somewhere else, she just won’t carry it. Second, a third party library must be declared in order to be instantiated in the application.
To start, state the location where you installed the mPDF
. This is the most delicate part, because here you will have to indicate exactly where he saved the vendor of mPDF
. The example below is in an environment Linux
, but serves for any operating system. I added the following at the end of application/config/constants.php
:
defined('MPDF') or define('MPDF', "/usr/share/php/mpdf/mpdf-7.1.9/vendor/autoload.php");
Once done, save the library statement in the file application/libraries/Mpdf.php
:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mpdf {
public $method;
function __construct() {
require_once MPDF;
$this->method = new \Mpdf\Mpdf();
}
}
Load the declared library with autoload in application/config/autoload.php
:
$autoload['libraries'] = array(
'mpdf'
);
Example of use in a method of a controller:
function export() {
$filename = 'sample.pdf';
$html = '<html><body><p>Put some html here!</p></body></html>';
$this->mpdf->method->SetTitle($filename);
$this->mpdf->method->SetAuthor('Author name here');
$this->mpdf->method->SetCreator('Creator name here');
$this->mpdf->method->SetSubject('Testing mPDF create functionality on this system');
$this->mpdf->method->WriteHTML($html);
$this->mpdf->method->Output($filename, 'D');
}
There, everything in its place, can not go wrong. Doing so, no matter in which environment you publish the code, will work.
OBS: any library PHP
can be loaded this way into a system made with CodeIgniter
v3.1.10.
has already run dump-autoload on the production server?
– Rafael Mena Barreto
@Rafaelmenabarreto not and honestly do not know how to do, I will search how to do or would have some tutorial link to send me? And it will not give problem with this command in other Ports that uses libraries installed via Poser?
– Thiago Moreira
You have installed mpdf by Composer?
– Rafael Mena Barreto
@Rafaelmenabarreto yes, I installed locally via Composer and when I went up to production it presents that error
– Thiago Moreira
Edit your question and add information see here. Show how you are loading the class to the application. Tell the versions of the libraries you are using. What is the difference between the local environment and the production environment? OS?
– ShutUpMagda