Extbase - externe Libraries

Aus Wikizone
Wechseln zu: Navigation, Suche

Zum Beispiel um FPDF oder mpdf oder ähnliche Libs zu nutzen.

Einfaches Einbinden über include oder require

require_once t3lib_extMgm::siteRelPath('your_extension_key') . 'Path/to/the/Script.php';

Library über ext_autoload.php einbinden

http://www.schmidtpublic.de/web-knowhow/article/pdf-mit-extbasefluid-erzeugen/

http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html

ext_autoload.php

$libraryClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('your_ext_key') . 'Relative/Path/Of/Your/External/Library/';
return array(
'class_name_to_call' => $libraryClassesPath . 'class_file.php',
);

An example using "FPDF"

Download the library and put it in /typo3conf/ext/myext/Resources/Private/Library/fpdf/

Save this code in /typo3conf/ext/myext/ext_autoload.php

    $libraryClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('myext') . 'Resources/Private/Library/';
    return array(
        'FPDF' => $libraryClassesPath . 'fpdf/fpdf.php',
    );
   clear the cache

use FPDF everywhere in your extension by calling:

    $pdf = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('FPDF');
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();