【问题标题】:TYPO3 8.7 Extbase generate csv-fileTYPO3 8.7 Extbase 生成 csv 文件
【发布时间】:2018-01-22 18:23:11
【问题描述】:

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

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

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

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 中发生了什么变化?

感谢您的帮助! 马丁

【问题讨论】:

    标签: typo3 extbase


    【解决方案1】:

    这里是我在 8.7 中如何发送电子邮件的 sn-p:

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

    /**
     * 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();
    }
    

    【讨论】:

      【解决方案2】:

      我通过稍微更改代码解决了这个问题,现在它可以工作了:

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

      【讨论】:

      • 看看我的答案,为模板、布局和部分的根路径提供更动态的解决方案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多