我正在寻找一种在用户添加错误输入时显示FlashMessage的方法。这段代码不起作用。感谢。
$t3type = \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE;
$header = "Notice";
$mes = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class,
$message,
$header,
$t3type,
true);
答案 0 :(得分:1)
试试这个TYPO3默认功能,
$this->addFlashMessage(
'Your message!',
'Description or something else..',
\TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING
);
希望这对你有用!问候!
答案 1 :(得分:1)
在控制器功能中添加它
$this->addFlashMessage(
$messageBody = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:yourextkey/Resources/Private/Language/locallang.xlf:error_body', 'yourextkey'),
$messageTitle = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT: yourextkey/Resources/Private/Language/locallang.xlf:error_title', 'yourextkey'),
$severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR,
$storeInSession = TRUE
);
并在流体模板中添加
<f:flashMessages />
在TYPO3核心API文档中可以找到更多内容: https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/FlashMessages/Index.html
答案 2 :(得分:0)
您可以像下面一样添加flashMessage。
$flashMessageTitle = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
'flashmessage_title_done',
$this->extensionName
);
$flashMessageBody = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
'flashmessage_description',
$this->extensionName
);
$this->addFlashMessage(
$flashMessageBody,
$flashMessageTitle,
\TYPO3\CMS\Core\Messaging\AbstractMessage::NOTICE,
true
);