yii\db\BaseActiveRecord::getAttributeLabel PHP Méthode

getAttributeLabel() public méthode

If the attribute looks like relatedModel.attribute, then the attribute will be received from the related model.
See also: generateAttributeLabel()
See also: attributeLabels()
public getAttributeLabel ( string $attribute ) : string
$attribute string the attribute name
Résultat string the attribute label
    public function getAttributeLabel($attribute)
    {
        $labels = $this->attributeLabels();
        if (isset($labels[$attribute])) {
            return $labels[$attribute];
        } elseif (strpos($attribute, '.')) {
            $attributeParts = explode('.', $attribute);
            $neededAttribute = array_pop($attributeParts);
            $relatedModel = $this;
            foreach ($attributeParts as $relationName) {
                if ($relatedModel->isRelationPopulated($relationName) && $relatedModel->{$relationName} instanceof self) {
                    $relatedModel = $relatedModel->{$relationName};
                } else {
                    try {
                        $relation = $relatedModel->getRelation($relationName);
                    } catch (InvalidParamException $e) {
                        return $this->generateAttributeLabel($attribute);
                    }
                    $relatedModel = new $relation->modelClass();
                }
            }
            $labels = $relatedModel->attributeLabels();
            if (isset($labels[$neededAttribute])) {
                return $labels[$neededAttribute];
            }
        }
        return $this->generateAttributeLabel($attribute);
    }