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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 C++使用TWAIN协议如何实现A3幅面扫描仪扫描A4横向
  • ¥15 如何在sql server里完成筛选
  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题