php - Magento 2成功默认消息在同一个phtml文件中
问题描述
单击提交按钮后,我想打印成功消息(Magento2 默认消息格式)。因此,如果所有字段都已验证,那么在同一 phtml 文件上应该有成功消息“您的数据已验证!”,我想知道如何从基本开始执行此操作,因为我不知道它::
我的块文件的代码::
` <?php
namespace Test\Validation\Block;
class Index extends \Magento\Framework\View\Element\Template{
protected $helper;
protected $_messageManager;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Message\ManagerInterface $messageManager,
array $data = []) {
parent::__construct($context, $data);
$this->_messageManager = $messageManager;
}
public function successmessage($message){
$this->_messageManager->addSuccess(__($message));
}
}`
~~谢谢,提前1!
解决方案
It should be done in a controller but not in the block. Look the example in the native magento contact module here \Magento\Contact\Controller\Index\Post
推荐阅读
- python - 如何将函数转换为一行
- angular - 如何强制 Angular 从后端重新获取特定 URL 的数据?
- php - PHP 致命错误:未捕获错误:调用未定义函数 openssl_verify()
- google-apps-script - 使用来自 ScriptService 的 Id Token 对 IAP(身份感知代理)进行 API 调用
- reactjs - Next.js - 浏览器返回 --- TypeError: Cannot read property 'split' of undefined
- python - 堆叠大型多索引 df 然后转换为 dict 的更快替代方案
- java - 如何在 java 中测量密码的 mb/s 速度?
- unity3d - Unity WebGL POST 请求在构建游戏后不起作用
- php - 使用 PDF2Text (PHP) 从 PDF 中提取文本
- sql - 初始化字符串的格式不符合从索引 132 开始的规范有问题