简体   繁体   English

无法在 TYPO3 v9 中获取后端用户

[英]Fetching backend user in TYPO3 v9 not possible

I worked with older TYPO3 versions (< v9)我使用较旧的 TYPO3 版本(< v9)

I am not able to fetch the logged in backend user in my frontend extension.我无法在我的前端扩展中获取登录的后端用户。 In earlier TYPO3 versions I was able to do that.在早期的 TYPO3 版本中,我能够做到这一点。

Now when I logged in in TYPO3 backend and ask for it now it won't work anymore.现在,当我登录 TYPO3 后端并要求它时,它现在不再起作用了。

My approach is:我的做法是:

$context = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);
$be_username = $context->getPropertyFromAspect('backend.user', 'username');

I am getting an empty string.我得到一个空字符串。 I know that backend user might be not available for FE.我知道后端用户可能无法使用 FE。 But I need to check on him.但我需要检查他。

Thank you for any suggestions.感谢您的任何建议。

If you want to find out if a Backend user is currently logged in, then the code is exactly right (you don't even need to check on the username).如果你想知道后端用户当前是否登录,那么代码是完全正确的(你甚至不需要检查用户名)。

$context = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);
$isLoggedIn = $context->getPropertyFromAspect('backend.user', 'isLoggedIn');

However, if you do this in your extension in a Plugin, that is cacheable ("USER" cObject, or a "non-cacheable action" in an Extbase Plugin), this information could be cached, which can lead to serious.但是,如果您在插件的扩展中执行此操作,即可缓存(“USER” cObject,或 Extbase 插件中的“不可缓存操作”),则此信息可能会被缓存,这可能会导致严重后果。 sideffects.副作用。

In general, you should only check for a backend user in Frontend-related events, PSR-15 middlewares or hooks from TSFE, not in plugins/cObjects etc. unless you really know what you are doing.一般来说,您应该只在与前端相关的事件、PSR-15 中间件或来自 TSFE 的钩子中检查后端用户,而不是在插件/cObjects 等中检查后端用户,除非您真的知道自己在做什么。

All the best, Benni-一切顺利,本尼——

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM