我创建了一个新的Yii2基础项目,并希望进行深入研究。
登录页面上有一个用户名字段:
我想将标签“用户名”更改为自定义标签,例如“我的一流标签”。我已经阅读了手册:http : //www.yiiframework.com/doc-2.0/yii-widgets-activefield.html
经过一番调查后,我得到了下一个结果:
我只更改了模板,它也更改了布局:
<?= $form->field($model, 'username', [
"template" => "<label> My superb label </label>\n{input}\n{hint}\n{error}"
])?>
如何以正确的方式更改标签的文字?什么是最佳做法?
好的,只需在LoginForm.php中覆盖attributeLabels即可:
/**
* Returns the attribute labels.
*
* See Model class for more details
*
* @return array attribute labels (name => label).
*/
public function attributeLabels()
{
return [
'username' => 'Логин',
'password' => 'Пароль',
];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句