你好,我正在研究 pimcore cms。
我在保存对象时调用自定义 API,它有一些自定义错误消息。
现在 pimcore 显示
“无法保存对象”。
如何在错误框中显示自定义消息而不是默认消息?
每当发生错误时,我的 API 都会返回错误消息,但我对如何使用 pimcore 错误消息传递它感到困惑。
我们将不胜感激您的帮助。
谢谢
我假设您正在使用 Pimcore 事件来实现您想要实现的目标。要显示自定义消息,您只需抛出 ValidationException,如下所示:
throw new \Pimcore\Model\Element\ValidationException("This is your custom error message", 1234);
Run Code Online (Sandbox Code Playgroud)
Example of custom error handling using the Event API此处的文档部分也对此进行了描述:
https://www.pimcore.org/docs/latest/Extending_Pimcore/Event_API_and_Event_Manager.html