基本上:每当用户输入的值不是有效的IPv4时,我想在BE中显示flash消息。我想在一个钩子里做这个,但是只使用Typo3文档中的代码来获取flash消息并不起作用,我的方面似乎有一个重大的误解。到目前为止,这是我的代码:
<?php
namespace Cjk\Icingaconfgen\Hook;
class EvalHook {
function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$pObj) {
if (!filter_var($fieldArray[IPv4], FILTER_VALIDATE_IP)){
//here i want to put the flash message code
}
}
}
?>
使用此处文档中的代码:
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class,
'My message text',
'Message Header', // [optional] the header
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, // [optional] the severity defaults to \TYPO3\CMS\Core\Messaging\FlashMessage::OK
true // [optional] whether the message should be stored in the session or only in the \TYPO3\CMS\Core\Messaging\FlashMessageQueue object (default is false)
);
添加以下行:
$message->render();
不起作用。我错过了什么?
答案 0 :(得分:0)
您是否尝试将FlashMessage添加到邮件队列?
use TYPO3\CMS\Core\Messaging\FlashMessageService;
// ... omitted some use statements
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
//...
$flashMessageService = $this->objectManager->get(lashMessageService::class);
$messageQueue = $flashMessageService->getMessageQueueByIdentifier();
$messageQueue->addMessage($message);
如果您在Controller中使用了闪存消息,那么您将不需要该部分。
https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/FlashMessages/Index.html