dongshai1944 2014-12-10 13:09
浏览 27
已采纳

CakePhp自定义翻译功能

I want to create a custom cakePhp function for translations.

My translations are stored in a database table.

What I would like to do is to get the translations from the database and put them in a PHP array at bootstrap. I would also like to define a global function __t() that acts like __() but fetches the translation from my custom php array instead of po files.

I have defined my __t function in Config/bootsrap.php, but how can I access the database from Config/bootstrap.php to load the data into the array?

  • 写回答

1条回答 默认 最新

  • dqwh0108 2014-12-10 14:46
    关注

    You need to use App::uses() to register classes you need and then instantiate the model:

    App::uses('ClassRegistry', 'Utility');
    $translationData = ClassRegistry::init('Modelname')->getTranslations();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?