TextField is empty if contains special language characters

Hello.

I had problem with CHtml::TextField - it should have shown expressions containing not only numbers and english characters, but also language-specific characters (czech republic). If these characters were present in TextField, than this TextField was blank - Yii did not fill it’s “value”. I solved it by changing function encode() in Yii framework. This function can be found in file: yii/framework/web/helpers/Chtml.php. It’s original content was this:




return htmlspecialchars($text,ENT_QUOTES,Yii::app()->charset);



and I changed it to return only the text:




return $text;



Everything worked well than.

In Yii is probably default and only value of Yii::app()->charset = UTF-8

I used "windows-1250" in layouts/main.php

In DB connection is set UTF-8 charset. (content of TextField came from DB)


UPDATE1:

Another solution was to change 3rd parameter of function htmlspecialchars(). Instead of Yii::app()->charset I entered ‘cp1251’ or ‘ISO-8859-1’. Maybe another charsets would work.


Is this solution OK? Can anyone pass judgment on it?

You can leave the framework as it is, you should never change a line in the folder framework.

I think that you can change Yii::app()->charset in config main:




<?php return array(

  'charset'=>'windows-1251';

   [...]



Or whaveter you want. I think that is anyway better to use UTF-8 anyway, there is a wiki about how to set it correctly.

Yeah… listen to zac, he knows what he says :)