2014-11-30 16 views
19

Stworzyłem nową Yii2 podstawowy projekt i chcą kopać wJak zmienić tekst etykiety ActiveField?

Jest pole Nazwa użytkownika na stronę logowania. enter image description here

Chcę zmienić etykietę „username” do jednego, na przykład zwyczaju "Moja znakomita wytwórnia". Czytałem instrukcję: http://www.yiiframework.com/doc-2.0/yii-widgets-activefield.html

Po zbadaniu trochę mam następny wynik: enter image description here

Zmieniłem tylko szablon i to zmieniła układ:

<?= $form->field($model, 'username', [ 
    "template" => "<label> My superb label </label>\n{input}\n{hint}\n{error}" 
])?> 

Jak zmienić tekst etykiety w prawidłowy sposób? Co to jest najlepsza praktyka?

Odpowiedz

18

porządku, po prostu zastąpić attributeLabels w LoginForm.php:

/** 
* Returns the attribute labels. 
* 
* See Model class for more details 
* 
* @return array attribute labels (name => label). 
*/ 
public function attributeLabels() 
{ 
    return [ 
     'username' => 'Логин', 
     'password' => 'Пароль', 
    ]; 
} 
19

istnieje inny fajny sposób.

<?= $form->field($model, 'username')->textInput(['class'=>'field-class'])->label('Your Label',['class'=>'label-class']) ?> 
+0

naprawdę pomogło to – azeem

2

Można również dodać taką funkcję do modelu

public function attributeLabels() 
{ 
    return [ 
     'username' => 'My Login', 
     'password' => 'My Pasword', 
     'rememberMe' => 'Remember Me, please', 
    ]; 
} 
Powiązane problemy