Cakephp, mysql and utf8 problem

Cakephp rocks. I just stared making a new site with cakephp and I already had a problem. The mysql encoding did not work properly for my language (greek). I made my database using utf8_unicode_ci but certain character appear wrong.
This is the solution:

Create a new file app_model.php, place it in your app folder. Put the following contents in the file:

PHP:
  1. class AppModel extends Model
  2. {
  3. function __construct($id=false, $table=null, $ds=null)
  4. {
  5. parent::__construct($id, $table, $ds);
  6. $this->execute( "SET NAMES 'UTF8'" );
  7. }
  8. }

if you are working with scaffolding, put this line in your cake/libs/view/templates/layouts/default.thtml:

PHP:
  1. echo $html->charset('UTF-8');

This info comes from: http://www.get-the-answer.info/comments.php?DiscussionID=5&page=1

Leave a Reply

You must be logged in to post a comment.