Laravel 5 字符集在视图上无法正常工作.但是当我从控制器转储它时它运行良好
我在这里遇到了字符集问题.我正在开发一个使用 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.
相关文章