十月CMS |如何关闭Flash消息或警报

时间:2017-08-12 20:45:22

标签: octobercms

在我的应用程序上,我需要抛出一些错误,所以在documentation之后,我可以使用以下代码抛出一些自定义消息的错误和/或渲染一些错误:

throw new AjaxException([
     '#error_box' => Lang::get('xxx.xxxx::lang.frontend.error_ajax_und')
]);

问题是我看到带有“默认文字”的Flash消息,我不知道如何将其关闭......

enter image description here

调试模式禁用

十月建造:419

1 个答案:

答案 0 :(得分:2)

理论上,您可以挂钩ajaxSetup事件来禁用闪存错误处理:http://octobercms.com/docs/ajax/javascript-api#global-events-examples

有些事情:

$(document).on('ajaxSetup', function(event, context) {
    // Disable AJAX handling of Flash messages on all AJAX requests
    context.options.flash = false
})

$(document).on('ajaxSetup', function(event, context) {
    // Handle Error Messages with a custom handler
    context.options.handleErrorMessage = function(message) {
        // do stuff
    }

    // Handle Flash Messages with a custom handler
    context.options.handleFlashMessage = function(message, type) {
        // do stuff
    }
})
相关问题