Get attribute label in yii2

How to get attribute label in yii2?

I got this getAttributeLabel() function here in yii2 document, I use this in the controller. But it causes an error

 Call to undefined function app\controllers\getAttributeLabel() 
+7
yii2
source share
2 answers

try it

 $model = new ModelName(); print_r($model->attributeLabels()); 

if you use the code above, you can get an array containing all the model attribute labels

+7
source share
 $task = new Task(); //to get single attribute label $label = $task->getAttributeLabel('task_title'); //to get all attribute label $labels = $task->attributeLabels(); 
+9
source share

All Articles