How do I include or autoload external libraries in a TYPO3 Extbase Extension? + Dependecy Injection?

本小妞迷上赌 提交于 2019-12-03 17:41:32

Extbase injection is pretty simple. Here's the actual implementation. Using external libraries, however, is not.

Once you figure out how to load the library, have you tried just injecting it? Like so:

/**
 * @var Facebook
 */
protected $facebook;

/**
 * inject the facebook
 *
 * @param Facebook facebook
 * @return void
 */
public function injectFacebook(Facebook $facebook) {
    $this->facebook = $facebook;
}

NOTE: You need the @param in the comment and you also need to clear your configuration cache after adding this code.

I don't know about the Facebook SDK API, but hopefully you can instantiate the Facebook object with the default constructor and then add the arguments later with setter methods. You might want to create a FacebookService class (singleton) that loads the Facebook PHP and sets the essential arguments. Then you can inject a FacebookService to get the actual Facebook object whenever you need it.

Bharat Parmar

First create ext_autoload.php in extension root folder

and add your code,it contain single dimension array with key as class name(class name must be prefix with extension key) and value as path to file. make sure clear your site

<?php

    $extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('rent_system');
    return array(   
        'rent_system_TCPDF' => $extensionPath.'Resources/Private/PHP/tcpdf/tcpdf.php',  
    );
?>

In controller file

$pdf = $this->objectManager->create('rent_system_TCPDF');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!