【发布时间】:2017-11-17 15:00:47
【问题描述】:
如何在 TYPO3 中显示未缓存的 fe_user 数据?根据Prevent to Cache Login Information。 如果用户登录,ViewHelper 设置 $GLOBALS['TSFE']->no_cache = 1。有没有更好的方法?因为不是整个页面不应该被缓存,只有部分页面。
【问题讨论】:
如何在 TYPO3 中显示未缓存的 fe_user 数据?根据Prevent to Cache Login Information。 如果用户登录,ViewHelper 设置 $GLOBALS['TSFE']->no_cache = 1。有没有更好的方法?因为不是整个页面不应该被缓存,只有部分页面。
【问题讨论】:
很遗憾,这是不可能的。
最好的方法是,您使用称为 eID 或 TypeNum 的 AJAX 呈现未缓存的 fe_user 数据,并且整个页面被完全缓存。 像这个: http://www.typo3-tutorials.org/cms/typo3-und-ajax-wie-geht-das.html
【讨论】:
您的示例代码禁用了整个页面的缓存。但您只需要为显示用户特定数据的部分禁用缓存。除了缓存中的任何部分,您可以选择是否仅缓存
ext_localconf.php 中将您的插件声明为不可缓存)COA_INT(或其他未缓存的对象))v:render.uncache() VH)[1] 由于 viewhelper 是从 AbstractConditionViewHelper 派生的,它使用 Compilable 接口,缓存结果,所以必须重写 AbstractConditionViewHelper 的 compile() 方法并返回常量
\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION
像这样:
public function compile(
$argumentsVariableName,
$renderChildrenClosureVariableName,
&$initializationPhpCode,
\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode,
\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler
) {
parent::compile(
$argumentsVariableName,
$renderChildrenClosureVariableName,
$initializationPhpCode,
$syntaxTreeNode,
$templateCompiler
);
return \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION;
}
【讨论】: