I use a MySQL database with charset ISO-8859-1 (latin1) because it must handle german umlauts and it must be case-insensitive (which is not possible with utf8). Everything worked fine but now I started to use CGridView in a view and there I get a problem:
When I open the view in the browser the german umlauts are first shown correctly but as soon as I use the pagination or the sorting (click on a link) the special characters are not shown correctly on the next result page. The html page is still ISO-8859-1 encoded so I think it is the database access of the widget.
You’re absolutely right. The cookbook is very helpful. In fact, I used it to adjust my charset settings, but at that time it was not necessary to adjust the .htaccess. And now that I ran into troubles again I thought: “I’ve already seen it, so I don’t have to read it again” …
I’m still having problems with this. I’m forced to use ISO-8859-1 because I’m building functionality on top of a monstrous legacy system. I’ve set the encoding in all the places mentioned in the cookbook including the .htaccess file. Now the CGridView search results all appear as they should.
However…
When I search for a multibyte character — for example, if I search for the city Köln, it replaces my search field with köln and doesn’t find the matching record.
I met the same problem! I simply added a converting line to the beginning of the search function:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$this->plName=mb_convert_encoding($this->plName, "ISO-8859-1", "UTF-8");
I used the solution mentionned by otaviofcs but because all my views files (and all my project files) are already encoded in utf-8, i do not mb_convert_encoding them.
I use utf8_decode instead (in my global layout or in any render_partial view) :
if(Yii::app()->charset == 'ISO-8859-1')
echo utf8_decode($content); // because all views files are encoded in UTF-8
else
echo $content;
This way, i always mention ‘utf8’ (and not utf-8 ) as database charset, so that i manipulate utf-8 strings server side.
At the last step, i check the Yii::app()->charset that i have to use and utf8_decode content to render if i need to.
I can finally easily switch from ISO-8859-1 to UTF-8 if i need to change the output encoded HTTP response.