A
A
alex stephen2015-12-11 14:48:33
PHP
alex stephen, 2015-12-11 14:48:33

Yii2 how to assign label to DynamicModel?

Hello.
Created a dynamic model for the form in Yii2. Everything works fine, but the field label is listed as " Phone ". Following the doc, I decided to write attributeLabels .
$model = new \yii\base\DynamicModel(['phone']);


$model->attributeLabels(['phone' => "Номер телефона"]);

However, nothing happened. No errors, no change of signature. So the cherished Phone still hangs .
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
totudub, 2015-12-11
@totudub

DynamicModel is used for dynamic validation. If you want to use labels, then make a regular model.
The attributeLabels() method is only used to get the labels of the attributes specified in the class.

K
Kirill Arutyunov, 2015-12-11
@arutyunov

It can be like this, for example:

$form->field($model, 'phone')->textInput()->label('Номер телефона');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question