Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

yii2 - 如何以yii2活动形式在占位符内使用Yii:t()(how to use Yii:t() inside placeholder in yii2 active form)

i'm trying to use a placeholder in my form with i will also want to translate base of user's language so i wrap it up in a Yii::t();

(我试图在我的表单中使用占位符,但我也想翻译用户语言的基础,所以我将其包装在Yii :: t();中。)

inside active form input attribute but the result i got is a plane string rather than a translated message below is my code:

(内部活动窗体输入属性,但我得到的结果是一个平面字符串,而不是下面的翻译消息是我的代码:)

<div class="input-group custom-d-flex">
    <span class="input-group-addon input-group-prepend"><i class="glyphicon glyphicon-user"></i></span>                     
    <?= $form->field($model, 'username')->textInput([
                          'autofocus' => false,
                          'class' => 'form-control',
                          'required' => true,
                          'placeholder' => "<?= Yii::t('app', 'email');?> / <?= Yii::t('app', 'id');?> / <?= Yii::t('app', 'phone');?>"
                    ])->label(false);
                    ?>
                </div>

and the result below

(和结果如下) 在此处输入图片说明

how to fix this?

(如何解决这个问题?)

thanks for any help

(谢谢你的帮助)

  ask by sam translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

占位符期望字符串:

'placeholder' => Yii::t('app', 'email') . ' / ' . Yii::t('app', 'id') . ' / ' . Yii::t('app', 'phone'),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...