如何覆盖laravel中刀片的默认逃逸功能5? [英] How to override default escape function of blade in laravel 5?

查看:208
本文介绍了如何覆盖laravel中刀片的默认逃逸功能5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎解决了我在。现在我必须找到一种方法来覆盖默认的刀片转义功能。
我认为有一种方法来创建扩展和覆盖BladeCompiler类的行为的类,这样我可以这样做:

I almost solved my problem in this question. Now I must find a way to override the default blade escape function. I think there's a way to create a class that extends and override the behavior of BladeCompiler class, this way I could make something like this:

class MyCustomCompiler extends BladeCompiler{
   function compileEscapedEchos($value){
        return parent::compileEscapedEchos(utf8_encode($value));
    }
}

如果我可以做到,我只需要做laravel使用MyCustomCompiler代替BladeCompiler。我如何做?

If I could do it, I only must make laravel use MyCustomCompiler instead BladeCompiler. How can I do it?

推荐答案

您甚至不必重写编译器,只需在服务提供商中执行此操作:

You don't even have to override the compiler, just do this in a Service Provider:

Blade::setEchoFormat('e(utf8_encode(%s))');

这将改变 {{...}} 被编译。默认格式为 e(%s)

This will change how {{ ... }} is compiled. The default format is e(%s).

这篇关于如何覆盖laravel中刀片的默认逃逸功能5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆