0

i've installed mpdf library with command composer require mpdf/mpdf.And it is installed in the location vendor/mpdf/src/Mpdf.php. And composer_autoload is true in config\autoload.php. with the below code, am getting the error Class 'Mpdf\Mpdf' not found. commenting use Mpdf\Mpdf; & uncommenting the lines i've commened below shows the error require_once(C:\xampp\htdocs\abcd\application\controllersvendor/mpdf/src/Mpdf.php): failed to open stream: No such file or directory.

My php version is 7.3.3.

How can i fix this? Can i get some help?

Controller

<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

use Mpdf\Mpdf;
//use \Mpdf\Mpdf;  //error- Class 'Mpdf\Mpdf' not found

<!--For the below 3, the error/warning is - `failed to open stream: No such file or directory` -->

//require_once __DIR__.'vendor/mpdf/src/Mpdf.php';  
//require_once __DIR__ . '/vendor/autoload.php';
//include_once('/mpdf/mpdf.php');

class Reports extends Layout_Controller
{
   public function downloadReport(){
        $fileName=$this->input->get('var');
        $mpdf=new Mpdf();
        $html=file_get_contents('reports/'.$fileName);
        $mpdf->WriteHTML($html);
        $mpdf->Output();
                
    }
}

composer.json

"require": {
        "php": ">=5.3.7",
        "mpdf/mpdf": "^8.0"
    }

Lines commented in this code are what i've tried .

1 Answers1

1

you still have to require_once 'vendor/autoload.php'; above your code.

This file is generated by composer and contains the information of autoloadable classes and the associated files.

daniel
  • 273
  • 2
  • 7
  • 1
    thank you very much. May i ask u y removed directory name from that require statement –  Jan 29 '22 at 15:39
  • the line `file_get_contents('reports/'.$fileName);` shows the error `file_get_contents(reports/download_advertiser_report_view.php): failed to open stream: No such file or directory` –  Jan 29 '22 at 15:43
  • Can u tell why this error. this file `download_advertiser_report_view.php` exists in the folder `views\reports` –  Jan 29 '22 at 15:45
  • file_get_contents('views/reports/'.$fileName); ? – daniel Jan 29 '22 at 15:56
  • Same error for `file_get_contents('views/reports/'.$fileName);` –  Jan 29 '22 at 15:58
  • Use full path like this example: `file_get_contents(__DIR__ . '/../../views/reports/'.$fileName);` while `__DIR__` is the directory of your php-file. now you must find out the correct path. – daniel Jan 29 '22 at 16:02
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Abhishek Jain Jan 29 '22 at 20:07