問題描述
我在這里遇到了字符集問題.我正在開發一個使用 sql server 數據庫的應用程序.數據庫不是為此應用程序創建的,它存在于它之前并且運行良好.我無法更改數據庫中的任何內容,因為它太大并且被許多其他應用程序使用.
我已經完成了 laravel 5 應用程序的身份驗證,因此我將創建一個視圖并在該視圖中顯示登錄用戶的名稱.名字是:ADMINISTRADOR DA ACENTUA??O.它使用了一些特殊字符.
在我看來:
I'm facing a charset problem here. I'm developing an app that uses a sql server database. The database was not created for this app, it exists before it and works very well. I can't change anything on the database because its too large and its used by many other apps.
I've been finished the auth of my laravel 5 app, so I'll create a view and show in this view the name of logged user. The name is: ADMINISTRADOR DA ACENTUA??O. It use some special characters.
In my views:
{!!Auth::user()->name!!}
顯示:
ADMINISTRADOR DA ACENTUA O
ADMINISTRADOR DA ACENTUA??O
但在我的控制器中,在返回視圖之前,我做了:
But in my controller, before I return the view, I did:
die(Auth::user()->name);
它告訴我:
ADMINISTRADOR DA ACENTUA??O
ADMINISTRADOR DA ACENTUA??O
我現在嘗試在我的視圖文件中執行此操作:
I try now do it in my view file:
{!!Auth::user()->name!!}
<?php die();
這很好用.它顯示給我:
And this works fine. It shows me:
ADMINISTRADOR DA ACENTUA??O
ADMINISTRADOR DA ACENTUA??O
這讓我相信錯誤是由 laravel 在解析視圖后所做的事情引起的.
It makes me believe the error occours for something laravel does after the views are parsed.
我不知道為什么當我死掉控制器上的用戶名時它運行良好,但當我在視圖上回顯其名稱時不起作用.
I don't know why it works well when I die the user name on the controller, but not works when I echo its name on the view.
有人可以幫我嗎?
附注:
- 我的視圖文件使用的是 utf8 字符集
- 我嘗試使用和不使用 html 標簽和字符集元進行回顯.兩種情況都會出現問題
- 我試圖刪除我的視圖文件并使用 utf8 字符集創建一個新文件.它不起作用.
- 我嘗試使用
<?php echo Auth::user()->name;?>
而不是刀片標簽.它不起作用.
- My view file is using utf8 charset
- I tried to echo with and without html tags and charset meta. The problem occours on both cases
- I tried to delete my view file and create a new one with utf8 charset. It doesn't work.
- I tried to use
<?php echo Auth::user()->name; ?>
instead blade tags. It doesn't work.
推薦答案
我使用這個答案解決了這個問題.我剛剛進入我的 AppServiceProvider 并進入引導方法:
I solved this issue using this aswer. I've just went in my AppServiceProvider and put into boot method:
Blade::setEchoFormat('e(utf8_encode(%s))');
我不知道這是否是正確的方法,但它對我有用.
I don't know if this is the correct way to do it, but it works for me.
這篇關于Laravel 5 字符集在視圖上無法正常工作.但是當我從控制器轉儲它時它運行良好的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!