Using special chars in Yii Apps


I’m quite new to Yii and currently working on my first project. As it is for a German user audience I need to use the German special chars like ‘ä,ü,ü,ß’. I would in common escape them by hand as e.g. ‘ä’ for ‘ä’. But unfortunately Yii would escape the ‘&’ char then - but it does not escape the German special characters.

Is there any way to either turn off automatically escaping (so the & char would not be escaped) or to add automatical escaping to the German special chars?

Here is an example:



		array('label'=>'Passwort ändern', 'url'=>array('/site/password')),

I need the output ‘Passwort ändern’ but it is either not escaped if written just like above or ‘Passwort ändern’ if I escape it by hand.

Thank you in advance!

Every part of Yii has well documented if it encodes his value or not…

For example chek the item label property documentation -

The encoding depends on "encodeLabels"

Also read this:

Thank you for your answers!

After analyzing everything I found out the best solution (at least for me):

Change the following function in the CHTML class:

public static function encode($text)


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


I replaced htmlencode() with htmlentities(). I see no need in replacing only the HTML-related stuff instead of everything. And migrating everything to UTF-8 is senseless as long as IE6 users are still out there ;)

Why? IE6 should work just fine if you set up everything correctly.

The only solution is to write all utf-8:

  • all files (localization files, models, controllers, views) should be utf-8 WITHOUT BOM

  • database should be utf-8 (collation utf-8-general-ci i.e.)

  • database connection should be utf-8

  • set names utf-8

If you work properly and carefully day by day, you will never have problem with encoding.

If you want, you can use another charset, but remember to change everithig accordingly.

I worked in italy for some year, and in italian like in german there are only a fiew special chars, so if it all looks correctly, you can avoid the problem.

As I moved in russia, I learned how to work correctly with encoding, here there are no possibility to “half solution”! :D