0
votes

I am new to CakePHP. I try to create a select box in PHP. But When I add unicode text to options value, the box get empty options.

Here is explain with code:

This code give 2 blank options, and empty option as "Select City":

**$cities = array('1'=>'Hà Nội','2'=> 'Hồ Chí Minh');**
echo $this->Form->input('city_id', array(
'label' => __d('users', 'City'),
'options' => $cities,
'empty' => __d('users', 'Select City'),
));

These codes give correct options:

**$cities = array('1'=>'Ha Noi','2'=> 'Ho Chi Minh');**
echo $this->Form->input('city_id', array(
'label' => __d('users', 'City'),
'options' => $cities,
'empty' => __d('users', 'Select City'),
));

Please note the different line of code: $cities = array('1'=>'Ha Noi','2'=> 'Ho Chi Minh');

I appreciate your helps.

3
Try in the same document write 'Hà Nội' in echo command. If the problem will be still, You have problem with encoding filekicaj

3 Answers

0
votes

You need to save your file as UTF8 if it contains UTF8 chars (or use proper i18n locale translation).

0
votes

Do you have following in your layout.. if not then try adding it:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 

Hope it helps

And if it will not work for you than at the end you can try using normal select tags instead of using cakephp's input tag for select, and it might solve your problem.

let me know if i can help you more.

0
votes

I had changed the database configuration file. It worked for me. I don't know why we set encoding for the site there. I uncommented this line:

'encoding' => 'utf8',