Laravel 5字符集不能正常工作的意见。但它工作良好,当我从控制器转储 [英] Laravel 5 charset not working correctly on the views. But it working well when I dump it from controller
问题描述
我在这里面临一个charset问题。我正在开发一个使用sql server数据库的应用程序。数据库不是为这个应用程序创建的,它之前存在,工作非常好。我无法更改数据库上的任何内容,因为它太大,并且已被许多其他应用程序使用。\\
我已经完成了我的laravel 5应用程序的验证,所以我将创建一个视图,在此视图中显示已登录用户的名称。名字是:ADMINISTRADOR DAACENTUAÇÃ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 DAACENTUA O
ADMINISTRADOR DA ACENTUA��O
但在我的控制器中, view,I did:
But in my controller, before I return the view, I did:
die(\Auth::user()->name);
并显示我:
ADMINISTRADOR DAACENTUAÇÃO
ADMINISTRADOR DA ACENTUAÇÃO
我现在尝试在我的视图文件中执行:
I try now do it in my view file:
{!!Auth::user()->name!!}
<?php die();
这很好。它显示我:
ADMINISTRADOR DAACENTUAÇÃ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.
任何人可以帮助我plz?
May anyone help me plz?
PS:
- 我的视图文件正在使用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.
推荐答案
我解决了这个问题,使用 this aswer 。我刚刚进入我的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字符集不能正常工作的意见。但它工作良好,当我从控制器转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!