how to change attribute labels in DynamicModel

hi there

how can i change attribute labels in DynamicModel ?

thanks a lot

Use attributeLabels() to define the array of all attributes names (name => label).

thanks but not working !

this is the code:

$model = \yii\base\DynamicModel::validateData(['count'],[

    ['count', 'required'],

    ['count', 'integer'],


$model->attributeLabels(['count' => 'تعداد کاربر']);

Oh, sorry - yes, you can not use it that way.

Why do you need to set the labels for DynamicModel?

If this is because of error messages you can set the message directly in the rule declaration.

both in error messages and the input label, my language is not english and i need to specify a label for the attribute.

thanks for your time

try this:

$required = ['count', 'required',"message"=>"My message here"];

$model = \yii\base\DynamicModel::validateData(['count'],[



I’m not sure if you should use DynamicModel for the form. Anyway - you can always chain label() method for the view form field to set label.