如何使用 CakePHP 的控制台烘焙 UTF-8 文件?
由于某种原因,我使用 CakePHP 控制台烘焙的每个文件都被视为由我的 IDE Dreamweaver 编码的 ISO-8859-1。这工作得很好,直到我最终输入一个特殊字符,该字符将被浏览器错误地显示,因为它的编码(由编辑器)与整体渲染不同。
如何强制控制台生成 UTF-8 文件(如果需要的话还带有 BOM)?
我已经尝试过转换用于烘焙标准脚手架页面的模板文件,但没有成功。
For some reason, every file that I bake with CakePHP's console is regarded as ISO-8859-1 encoded by my IDE Dreamweaver. This works fine up to the point where I end up typing a special character, which will be wrongly displayed by the browser, since its encoding (by the editor) differs from the overall rendering.
How can I force the console to produce UTF-8 files, with a BOM if necessary?
I've already tried converting the template files that are used to bake the standard scaffolding pages, but with no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有同样的问题 - 烘焙文件不是 UTF-8 而是 ASCII。 (使用notepad++编辑器,它可以轻松转换,以另一种格式保存文件)。
烘焙生成文件后,我必须将它们一一转换为 UTF-8,以便能够使用波兰本地字符。
我尝试将模板文件更改为 UTF-8,但不知何故这没有帮助。这可能与默认文件不包含任何非 ASCII 字符有关,因此即使保存为 UTF,它们仍然是 ASCII。
我发现克服这个问题的最简单方法是修改模板文件,例如。
蛋糕\控制台\模板\默认\类\model.ctp
在某处包含 utf-8 字符,例如:
//'消息' => '这里是您的自定义消息 ł',
(注意行尾的最后一个非 ASCII 字符。
然后转换并保存为 UTF-8 确保模板文件是 utf-8。
现在,模型文件生成为 UTF-8。
I have the same problem - baked files are NOT UTF-8 but ASCII. (use notepad++ editor which allows easily convert, save files in another format).
Once bake generates files I have to convert them to UTF-8 one by one, to be able to work with Polish local characters.
I tried changing template files to UTF-8 but somehow this does not help. This may have something to do with the fact that the default file does not contain any non ascii character, therefore even if saved as UTF they stay ASCII.
The simplest way I found to overcome this is to modify template file eg.
cake\console\templates\default\classes\model.ctp
to include utf-8 character somewhere, e.g.:
//'message' => 'Your custom message here ł',
(notice last non ASCII character at the end of line.
then converting and saving as UTF-8 makes sure template file is utf-8.
now, model files are generated as UTF-8.
烘焙文件是 UTF-8,或者更确切地说,它们仅包含与基本 UTF-8 范围相同的基本 ASCII 字符,因此可以视为其中之一。这是 Dreamweaver 的问题,而不是
bake
的问题。检查 Dreamweaver 设置(或在合适的编辑器中编写代码;-P)。您不想想要包含BOM,它稍后会把您搞砸。
The baked files are UTF-8, or rather, they only contain basic ASCII characters which are identical to the basic UTF-8 range, so can be regarded as either. It's Dreamweaver's problem, not a problem with
bake
. Check the Dreamweaver settings (or code in a decent editor ;-P).You do not want to include a BOM, it'll screw you over later.
使用Bake_UTF8插件 =]
http://www.github.com/pedroelsner/bake_utf8
我希望这会有帮助的。
佩德罗·埃尔斯纳
Use the Bake_UTF8 plugin =]
http://www.github.com/pedroelsner/bake_utf8
I hope this be helpfull.
Pedro Elsner
实现此目的的另一种方法是打开生成 UTF-8 内容(不带 BOM)的 PHP 文件,然后使用 Notepad++ 将它们保存为带 BOM 的 UTF-8 格式(编码-> 以 UTF-8 编码)
在我的例子中,我有 Excel CSV 文件:
然后我必须将 PHP 文件的编码转换为堆栈:
转换这些文件的编码后,它会生成可读的 UTF8 excel 文件
Another way to achieve this is to open PHP files that are producing UTF-8 content (without BOM) and then saving them in format UTF-8 with BOM using Notepad++ (Encoding->Encode in UTF-8)
In my case I had Excel CSV file:
Then I had to convert encoding of PHP files down the stack:
After conversion of encoding of these files it produces readable UTF8 excel files