Many people want to use the so called special characters. I am not sure why are they so special, it seems perfectly reasonable to have other-than-english characters, like umlauts (A1). Being a native non-english speaker, I can understand this perfectly (try getting the letter "Č" with the english character set!). The solution to this problem is UTF-8. Luckily for us, CakePHP 1.2 supports all kinds of crazy stuff with no trouble.
In a few shorts steps:
Source code
Start with your source code. Are your files saved as UTF-8? If not, they should be. This will enable you to use "special characters" in your code (flash messages, etc..)
Database tables
Make sure all your tables and fields have encoding set to utf8.
Database connection(s)
CakePHP has a very nice option for setting the database encoding automagically, just use the following line in your database config:
class DATABASE_CONFIG { var $default = array ( 'driver' => 'mysql', 'connect' => 'mysql_connect', 'host' => 'localhost', 'login' => 'root', 'password' => '', 'database' => 'neutrinocms_beta', 'prefix' => '', 'encoding' => 'utf8' // <-- easy! ); }
Application config
Make sure your application is indeed serving pages as UTF-8. In your ~/app/config/core.php use this:
Configure::write('App.encoding', 'UTF-8');
Also check you have this in your layout (in the <head> section):
<?php echo $html->charset(); ?>
That should do it. Your application should now accept any "foreign" characters you input, or write in your code. Is it not lovely to work with CakePHP magic?
Happy baking!
Article comments — View · Add
I have a function inside a component, which returns an array.
The key and the value of a pair has special characters.
In the controller I then set this array to a $variable to render.
And in the view I use this $variable as the options of a select input.
$form->input(model.field, array('options' => $variable)).
But the option that has the special character is not rendered.
é or whatever
Since your function is returning an array, you have to check the source of your data. Do the array values come from the database? Or are they hard-coded in your component?
If they are hard-coded, re-check the file encoding of your component. If they come from the database, check the encoding of your DB connection, database tables/fields, and last but not least, make sure those values are entered correctly in the database.
This is all I can think of right now.. Try using Cake's own debug tools and Firebug if you're not already, that ought to help in search for clues.