Strange problem with CGridView encoding

I have possibly strangest thing I ever run into with Yii. I don’t know what happened, so I don’t know if this is or isn’t Yii related.

Suddenly my CGridView started to display incorrectly encoded UTF-8 national characters and for the reason beyond my understanding started to captialize first letter in each word in each header.

So the code for columns of CGridView is:


'selectableRows'=>1,

'columns'=>array

(

    	'ROWNUMID:text:L. p.',

    	array

    	(

            	'name'=>'test',

            	'type'=>'raw',

            	'value'=>'$data->NAZW." ".$data->IMIE',

            	'htmlOptions'=>array('style'=>'text-align: left'),

    	),

    	'PLEC',

    	array

    	(

            	'name'=>'ęóąśłżźćń ĘÓĄŚŁŻŹĆŃ',

            	'type'=>'raw',

            	'value'=>'CFR::generatePatientBornDiv($data->PESL, $data->UDAT)',

    	),

    	'ZLCCNT'

),

And the actual result you can see in screen capture:

1359

cgridview-encoding.png

Notice, that ‘pacjent’ has first letter uppercased, and that there is garbage in place of test Polish letters.

The strangest part is for field "PLEC", which has name defined in Model class and this name contains "ł" Polish national letter and this letter is printed correctly, why in the very same time, in second column, the very same letter is printed incorrectly.

Both model and view files are correctly coded in UTF-8. As Netbeans uses this by default. In fact all my files are encoded in UTF-8 and nothing has ever changed in this matter for months.

I’m completely out of ideas what could happen and how to work this out?

Do you still have a var_dump or something like that anywhere in your controllers/models? This sometimes mixes encoding up without actually seeing any output.

No, because I don’t use var_dump in any of my project. If I need to print out / debug some variable, I use print_r or echo.

All right, I found the source of the problem.

I was my mistake. I mistakenly used CGridView.column (CDateColumn to be more precisely) name element instead of header element like I should. This caused Yii to look for a Model field with that strange name and, since it was not found, to call CModel.generateAttributeLabel() method, which uses PHP’s ucwords function.

I still wonder if fact that generateAttributeLabel() uses ucwords instead of mb_convert_case() – isn’t a bug. In fact, we’re all open to UTF, why don’t we use functions that supports it? But that is a question to Yii Dev Team! :]