Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorjervis
     
    how to set the connection to the database, where should I plus the 'SET NAMES utf8'?

    in the model ?
    •  
      CommentAuthorbermi
     

    I wouldn't put it in the model.

    The best way if you have control over the server is to edit /etc/my.cnf and add

    init_connect='SET NAMES utf8'
    

    or you could implicitly call this in your app/application_controller.php

    class ApplicationController extends AkActionController
    {
        function __construct()
        {
            $this->beforeFilter('_configureMySqlCharset');
        }
        function _configureMySqlCharset()
        {
            $db =& Ak::db();
            $db->Execute('SET NAMES utf8');
        }
    }
    

    or set UTF8 in your migrations for each database table using

    function up_2()
    {
        $this->db->Execute("ALTER DATABASE table_name SET CHARACTER SET utf8;");
    }
    

    As Akelos is utf8 by default we might consider automating this in a future, but keeping in mind that it is only supported after MySQL 4.1

    • CommentAuthorjervis
     
    thank you, bermi
    • CommentAuthortom
     

    Hi,

    init_connect='SET NAMES utf8'
    

    seems to work for me as well...

    Cheers,

    Tom

    • CommentAuthortanaka
     

    I found a strange phenomenon about this topic.

    $_SESSION['__flash'] is always empty when

    define('AK_SESSION_HANDLER', 1);
    

    and

    class ApplicationController extends AkActionController
    {
        function __construct()
        {
            $this->beforeFilter('_configureMySqlCharset');
        }
        function _configureMySqlCharset()
        {
            $db =& Ak::db();
            $db->Execute('SET NAMES utf8');
        }
    }
    

    in application_controller.php.

    In this situation, Akelos sends queries in order below.

    1. SELECT value FROM sessions WHERE id = [value of AK_SESSID]
    2. SET NAMES utf8
    

    And, as a result, "flash()" doesn't work. $_SESSION['__flash'] is always empty.

    So, I put this code in config/boot.php and don't use "beforeFilter('_configureMySqlCharset')" in ApplicationController.

    // set names charset
    if (!defined('AK_SET_NAMES')) {
        require_once(AK_LIB_DIR.DS.'AkActiveRecord.php');
        global $dsn;
        $dao =& Ak::db(&$dsn);
        $dao->Execute('set names utf8');
        unset($dao);
        define('AK_SET_NAMES', true);
    }