問題描述
我在這個問題.現在我必須找到一種方法來覆蓋默認的刀片轉義功能.我認為有一種方法可以創建一個擴展和覆蓋 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中刀片的默認轉義功能?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!