Ad

October CMS Include Class

- 1 answer

I want to use FPDF class in my october plugin for create PDF from some record data. In my plugin directory i create classes folder and here i create fpdf.php class and set namespace

namespace Author\Pluginname\Classes; 

In my controller i use

use Author\Pluginname\Classes\TCPDF;

and create public function createPdf($id) where i set

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

But i get error Class 'Author\Pluginname\Classes\TCPDF' not found

Full controller

<?php namespace Author\Pluginname\Controllers;

use Backend\Classes\Controller;
use BackendMenu;
use Author\Pluginname\Classes\TCPDF;

class Reservations extends Controller
{
    public $implement = ['Backend\Behaviors\ListController', 'Backend\Behaviors\FormController'];

    public $listConfig = 'config_list.yaml';
    public $formConfig = 'config_form.yaml';

    public function __construct()
    {
        parent::__construct();
    }

    public function createPdf($id)
    {
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    }
}

What I do wrong?

Ad

Answer

I guess there is file name issue.

Directory structure and File Name should look like this.

enter image description here

Your FPDF.php file code should look like this.

enter image description here

<?php namespace HardikSatasiya\SoTest\Classes;

class FPDF {

    public static function hello() {
      echo "<pre/>";print_r('its ok');exit();
      // .. other code
    }

    // .. other code

}

You can use it like this

enter image description here

use HardikSatasiya\SoTest\Classes\FPDF;

function onStart() {

    $fpdf = new FPDF();
    // .. other code
}

Then it should work properly.

If any doubt please comment.

Ad
source: stackoverflow.com
Ad