• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting up FPDI_Protection in CI 4 [namespace giving me a challenge]

#1
I am trying to generate a pdf( using FPDI_Protection) in CI 4 but i keep getting this error 

"Class 'FPDF' not found
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}"



Quote:In my client controller i have

Code:
namespace App\Controllers;
use CodeIgniter\Controller;

use App\Libraries\pdf\fpdf;
use App\Libraries\pdf\fpdi;
use App\Libraries\pdf\FPDI_Protection;

class Client extends Controller{
protected $pdf;
function __construct(){
    helper('url');
   $this->pdf = new FPDI_Protection();
}
public function download_invoice($client_code){
   
    $this->pdf->SetProtection(array('print'),'12345','');
    $this->pdf->AddPage();
    $this->pdf->SetFont('Arial');
    $this->pdf->Write(10,'blah blah blah blah blah blah blah.');
    $this->pdf->Output('D', 'test_invoice.pdf', true);
  }

}
   







Quote:FPDI_Protection.php  file link here
PHP Code:
namespace App\Libraries\pdf//I included this namespace 
use App\Libraries\pdf\fpdf// but this class cannot be found
use App\Libraries\pdf\fpdi;
/*****************************************************************************
 * Software: FPDI_Protection                                                 *
 * Version:  1.0.6                                                           *
 * Date:     2016/01/04                                                      *
 * Author:   Klemen VODOPIVEC, Jan Slabon                                    *
 * License:  Freeware                                                        *
 *                                                                           *
 * You may use and modify this software as you wish as stated in original    *
 * FPDF package.                                                             *
 *                                                                           *
 * Infos (by Jan Slabon):                                                    *
 * This class extends the FPDI-class available at https://www.setasign.com   *
 * so that you can import pages and create new protected pdf files.          *
 *                                                                           *
 ****************************************************************************/

class FPDI_Protection extends FPDI
{
 
 //Never mind the code inside i excluded it for this thread





Quote:fpdi.php file 
PHP Code:
<?php
namespace App\Libraries\pdf//I included this namespace
/**
 * This file is part of FPDI
 *
 * @package   FPDI
 * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
 * @license   http://opensource.org/licenses/mit-license The MIT License
 * @version   1.6.2
 */

if (!class_exists('FPDF_TPL')) {
    require_once('fpdf_tpl.php');
}

/**
 * Class FPDI
 */
class FPDI extends FPDF_TPL
{
 
//Never mind the code inside i excluded it for this thread

Quote:fpdf.php file
PHP Code:
<?php
namespace App\Libraries\pdf;
/*******************************************************************************
* FPDF                                                                         *
*                                                                              *
* Version: 1.81                                                                *
* Date:    2015-12-20                                                          *
* Author:  Olivier PLATHEY                                                     *
*******************************************************************************/

define('FPDF_VERSION','1.81');

class 
FPDF
{
////Never mind the code inside i excluded it for this thread


Error when generating the pdf file is as follows:

"Class 'FPDF' not found
#0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#1 {main}"
Reply

#2
you need to add the library path to autoload config and your classes to the classmap : https://codeigniter4.github.io/CodeIgnit...oader.html

your should psr4 looks like this:

PHP Code:
$psr4 = [
 
'Config'      => APPPATH 'Config',
 
APP_NAMESPACE => APPPATH               // For custom namespace
 
'App'         => APPPATH               // To ensure filters, etc still found,
 
'Libraries' => APPPATH.'Libraries',
 ]; 

and your classmap like this:

PHP Code:
$classmap = [
'FPDF'    => APPPATH.'Libraries/pdf/fpdf.php'
'FPDI'  
=> APPPATH.'Libraries/pdf/fpdi.php' 
]; 

not sure if you need both^^ but you should add your main class to the classmap, that is accessed from outside the pdf directory ( library )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.