A fusion of technology, music, and geekyness.

CakePHP Character Encoding Checklist

I was having some issues today with character encoding and I thought I’d post about it. There are three elements that you need to make sure you have if you want to properly use UTF-8 character encoding in your Cake app. My issue was that I did not have #2, although adding #1 didn’t hurt either.

1. Database Config

Add ‘encoding’ => ‘utf8′ to app/config/database.php

	var $default = array(
		'driver' => 'mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'user',
		'password' => 'password',
		'database' => 'database',
		'encoding' => 'utf8'
	);

2. Make sure your layout has the charset line in the

	<head>
	 	<?php echo $html->charset(); ?>
	 	Other elements...
	</head>

3. This one is set by default, but make sure App.encoding is set in app/config/core.php

/**
 * Application wide charset encoding
 */
	Configure::write('App.encoding', 'UTF-8');

And thats it!

Leave a Reply

Powered by Wordpress | Designed by Elegant Themes