douyin6188 2017-01-02 02:53
浏览 39
已采纳

PHP MVC:如何向视图添加翻译字符串?

In my MVC view files, there exist strings I may have a translation for. In a file with access to the database (the model), I can do:

$Lang->say('Welcome');

Here is what it's doing:

public function say($string) {

    if (empty(self::$vocabulary)) {
        self::$vocabulary = $this->loadLanguage($this->currentLanguageID()); // Load vocabulary for current language
    }

    if (isset(self::$vocabulary[$string])) {
        return self::$vocabulary[$string];  
    } 

    return $string;

}

I need access to this say() function from within my view. Short of passing the entire vocabulary array to the view, how would I do this?

  • 写回答

1条回答 默认 最新

  • dongzhong9055 2017-01-02 03:03
    关注

    What you need to do is require_once() your .php file that contains your class. You can then instantiate your class into a object like $Lang and call $Lang->Say() from your view.

    For example:

    require_once("file_that_holds_class.php");
    
    $Lang = new classNameHere();
    $result = $obj->Say("whatever_string_value");
    
    echo $result;
    

    Now you can do whatever it is you need to do with the string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测