TYPO3 6.2带有非命名空间类的ext_autoload

时间:2014-07-01 15:42:39

标签: php extbase typo3-6.2.x

我正在尝试在TYPO3 6.2中创建一个新的Extbase扩展,并且我没有包含现有的类/框架模块。

我的ext_autoload.php(ofc位于我的分机目录中)

$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('couponprinter');

return array(
    'ZendPdf' => $extensionPath . '/Classes/Utility/Zend/Pdf.php',
);

我正试图通过

在我的控制器中加载该类
$pdf = $this->objectManager->create('ZendPdf');

但是我得到错误“无法分析类:ZendPdf可能没有加载或没有自动加载器?”

Zend类本身有很多我不能重构的包含,所以我需要自动加载器。这是一个简短的片段:

/** Internally used classes */
require_once 'Zend/Pdf/Element.php';
require_once 'Zend/Pdf/Element/Array.php';
require_once 'Zend/Pdf/Element/String/Binary.php';
require_once 'Zend/Pdf/Element/Boolean.php';
require_once 'Zend/Pdf/Element/Dictionary.php';
require_once 'Zend/Pdf/Element/Name.php';
require_once 'Zend/Pdf/Element/Null.php';
require_once 'Zend/Pdf/Element/Numeric.php';
require_once 'Zend/Pdf/Element/String.php';

class Zend_Pdf{
// code of the class
}

由于TYPO3 6.2改变了一些旧方法,我不能再包括了。有没有人知道如何将一个非命名空间的类加载到extbase扩展中?

2 个答案:

答案 0 :(得分:0)

您需要创建一个ext_autoload.php文件并填充类似

的文件
<?php
$extensionClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('news') . 'Classes/';

$default = array(
        'tx_news_domain_model_dto_emconfiguration' => $extensionClassesPath . 'Domain/Model/Dto/EmConfiguration.php',
        'tx_news_hooks_suggestreceiver' => $extensionClassesPath . 'Hooks/SuggestReceiver.php',
        'tx_news_hooks_suggestreceivercall' => $extensionClassesPath . 'Hooks/SuggestReceiverCall.php',
        'tx_news_utility_compatibility' => $extensionClassesPath . 'Utility/Compatibility.php',
        'tx_news_utility_importjob' => $extensionClassesPath . 'Utility/ImportJob.php',
        'tx_news_utility_emconfiguration' => $extensionClassesPath . 'Utility/EmConfiguration.php',
        'tx_news_service_cacheservice' => $extensionClassesPath . 'Service/CacheService.php',
);
return $default;
?>

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

的文档中找到

答案 1 :(得分:0)

我想它应该是

$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('couponprinter');

return array(
    'zendpdf' => $extensionPath . '/Classes/Utility/Zend/Pdf.php',
);

数组的左侧(键)必须是小写的。