TYPO3 8.7 Extbase生成csv文件

时间:2018-01-22 18:23:12

标签: typo3 extbase

我尝试在TYPO3扩展程序中生成一个csv文件。我收到以下错误:

1225709595:无法加载Fluid模板文件“”。 (更多信息)

文件中抛出TYPO3Fluid \ Fluid \ View \ Exception \ InvalidTemplateResourceException 第719行/usr/local/www/apache24/xx/xx/vendor/typo3fluid/fluid/src/View/TemplatePaths.php。

25 TYPO3Fluid \ Fluid \ View \ TemplatePaths :: resolveFileInPaths(array,“Default”,“csv”)

我的控制器看起来像:

$icalView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
                $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);

$ icalView-> setFormat( 'CSV');

                $icalView->setTemplatePathAndFilename('typo3conf/ext/xxx/Resources/Private/Templates/Bestellung/Listbestellungen.txt'); 

                $icalView->assign('xx', $xx);

                $icalContent = $icalView->render();

我确实在... Bestellung中有Subfolter“Layout”并且我有文件Default.csv

相同的代码在TYPO3 7.6.x中的扩展名中工作 - 在8.7中有什么变化?

感谢您的帮助! 马丁

2 个答案:

答案 0 :(得分:1)

这里是我在8.7中发送电子邮件的代码片段:

据我所知,在选择要使用的模板之前,您还必须设置模板,布局和部分的路径

/**
 * configurationManager
 *
 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
 * @inject
 */
protected $configurationManager;

public function sendEmail($template,...)
{
    /**
     * Generate Email Body
     */

    $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);

    /** @var StandaloneView $emailView */
    $emailView = $this->objectManager->get(StandaloneView::class);
    $emailView->getRequest()->setControllerExtensionName($controllerExtensionName);
    $emailView->getRequest()->setPluginName($pluginName);
    $emailView->getRequest()->setControllerName($controllerName);

    $emailView->setTemplateRootPaths($extbaseFrameworkConfiguration['view']['templateRootPaths']);
    $emailView->setLayoutRootPaths($extbaseFrameworkConfiguration['view']['layoutRootPaths']);
    $emailView->setPartialRootPaths($extbaseFrameworkConfiguration['view']['partialRootPaths']);

    $emailView->setTemplate('Email/' . ucfirst($template));
    $emailView->assignMultiple($variables);

    $emailBody = $emailView->render();
}

答案 1 :(得分:0)

我通过更改代码解决了这个问题,现在它正在运行:

$storage = $this->resourceFactory->getDefaultStorage();
                if ($storage === NULL) {
                    throw new \RuntimeException('Could not get the default storage', 1475590001);
                }




                /** @var \TYPO3\CMS\Fluid\View\StandaloneView $icalView */
                $icalView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
                $icalView->setFormat('csv');

                $templateRootPath[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:xxx/Resources/Private/Templates/');
                $layoutRootPaths[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:xxx/Resources/Private/Layouts/');
                $partialRootPaths[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:xxx/Resources/Private/Partials/');

                $icalView->setLayoutRootPaths($layoutRootPaths);
                $icalView->setPartialRootPaths($partialRootPaths);
                $icalView->setTemplatePathAndFilename('typo3conf/ext/xxx/Resources/Private/Templates/Bestellung/Listbestellungen.txt');

                $icalView->assign('xxx', $xxx);

                $icalContent = $icalView->render();

                $tempFolder = $storage->getFolder('bestellungencsv');
                $tempFile = $storage->createFile('bestellungen_'.$xxx->getUid().'.csv', $tempFolder);
                $tempFile->setContents($icalContent);