Extbase - externe Libraries: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
Zeile 3: Zeile 3:
 
== Einfaches Einbinden über include oder require ==
 
== Einfaches Einbinden über include oder require ==
 
  require_once t3lib_extMgm::siteRelPath('your_extension_key') . 'Path/to/the/Script.php';
 
  require_once t3lib_extMgm::siteRelPath('your_extension_key') . 'Path/to/the/Script.php';
 +
 +
Test in 6.2 mit Namespace:
 +
require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('gbrma') . 'Resources/Private/Library/mpdf56/mpdf.php';
 +
$mpdf=new mPDF('c');
 +
Hat bei mir in TYPO3 6.2 nicht geklappt (require schon aber nicht das erzeugen eines neuen Objektes -> Fehler Class 'Geobit\Gbrma\Controller\mPDF' not found
 +
 
== Library über ext_autoload.php einbinden ==
 
== Library über ext_autoload.php einbinden ==
 
http://www.schmidtpublic.de/web-knowhow/article/pdf-mit-extbasefluid-erzeugen/
 
http://www.schmidtpublic.de/web-knowhow/article/pdf-mit-extbasefluid-erzeugen/

Version vom 6. August 2015, 09:35 Uhr

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';

Test in 6.2 mit Namespace:

require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('gbrma') . 'Resources/Private/Library/mpdf56/mpdf.php';
$mpdf=new mPDF('c');

Hat bei mir in TYPO3 6.2 nicht geklappt (require schon aber nicht das erzeugen eines neuen Objektes -> Fehler Class 'Geobit\Gbrma\Controller\mPDF' not found

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();