【问题标题】:Render Partial TemplateView in Typo3 using Extbase使用 Extbase 在 Typo3 中渲染部分 TemplateView
【发布时间】:2016-01-29 08:19:28
【问题描述】:

我想通过 Ajax 在 Extbase 控制器中延迟加载多个 PartialTemplate。 因此,我发现以下脚本仅呈现 Partials,但在我的上下文中不起作用:

 private function renderPartial($partialName='', $data = array()){
    if($partialName==''){
        throw new \TYPO3\CMS\Extbase\Mvc\Exception\RequiredArgumentMissingException('The Partial name must be defined.', 123456789);
    }
    $this->templateView = $this->objectManager->create('TYPO3\CMS\Fluid\View\TemplateView');
    $res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
    $this->templateView->setLayoutRootPath($res);
    $this->templateView->setPartialRootPath($res . 'Partials/');
    $this->templateView->setRenderingContext($this->objectManager->create('TYPO3\CMS\Fluid\Core\Rendering\RenderingContext'));
    $this->templateView->setControllerContext($this->controllerContext);

    return $this->templateView->renderPartial($partialName, Null, $data);
}

这会导致以下错误: 致命错误:在第 281 行的 /var/www/html/typo3_src-7.6.0/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php 中的非对象上调用了 __clone 方法

为此,我 Goolge 并发现许多帖子都有同样的问题。我能做些什么来使它工作。使用 StandaloneView 和 setTemplatePathAndFilename() 的解决方法效果很好。是否可以在没有布局/部分的情况下使用 Partial?

编辑:

我添加了一些调试信息和控制器操作...

public function searchAction(\PCON\Avm\Domain\Model\DemandSearch $demandSearch = NULL) {

    //GlobalSearch
    if($demandSearch != NULL) {
        $searchResult = $this->demandSearchRepository->findDemanded($demandSearch);
        $this->view->assign('searchResult', $searchResult);
    }

    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->controllerContext);
    $this->templateView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\TemplateView');
    $res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
    $this->templateView->setLayoutRootPath($res);
    $this->templateView->setPartialRootPath($res . 'Partials/');
    $this->templateView->setRenderingContext($this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext'));
    $this->templateView->setControllerContext($this->controllerContext);
    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->templateView);
    return $this->templateView->renderPartial('Search/SearchForm.html', Null, array('searchResult'=>$searchResult));
}

我不认为这是一个 AJAX 问题(由 PageNum 定义)。 如果我在没有 AJAX 的情况下调用控制器操作,则会出现相同的错误...

【问题讨论】:

  • 好吧,你应该调试你的方法,很难猜出你做了什么(你是如何初始化你的 AJAX 动作的……有合适的 Extbase 的上下文吗?)另一方面 StandaloneView 是自然的候选者用于渲染......独立的部分视图/部分等。
  • 嗨,感谢您的快速响应。我添加了一些额外的信息。我不认为这是一个 ajax 问题...

标签: ajax typo3 extbase


【解决方案1】:

您不能在 StandaloneView 中使用来自 extbase/php 的 renderPartial() 或 renderSection()。这是一个缺失的功能,可能不会在 TYPO3 7.6 及以下版本中实现。看到这个任务:https://forge.typo3.org/issues/54509

但是,您可以在 Fluid 中使用分部和部分。只需分配您的变量,然后使用

呈现您的模板
$this->templateView->render();

并在 Fluid 模板中使用部分和部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多