【问题标题】:Create Formatter class in Yii2在 Yii2 中创建 Formatter 类
【发布时间】:2016-03-08 14:04:57
【问题描述】:

我需要创建一个像下面这样的 Formatter 类:

echo \Yii::t('app', 'You are here for {n,duration} already!', ['n' => 47]);

例如,如果我写下:

echo \Yii::t('app', 'click here to open user profile {label,link}!', ['label' => $username,'href'=>"/userid?id=".$userId]);

它会打印出一个指向用户个人资料页面的链接。

【问题讨论】:

    标签: php yii2 formatter


    【解决方案1】:

    无需为此任务扩展类。

    用这样的链接包装翻译:

    $translation = \Yii::t('app', 'click here to open user profile ({label})!', ['label' => $username]);
    
    <?= Html::a($translation, ['userid', 'id' => $userId]) ?>
    

    【讨论】:

    • 谢谢,但出于某种原因,我想将它们结合在一起。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    相关资源
    最近更新 更多