Returns the text label for the specified attribute.
public getAttributeLabel ( string $attribute ) : string | ||
$attribute | string | the attribute name |
return | string | the attribute label |
// Define a model class class Post extends yii\base\Model { public $id; public $title; public $content; // Define attribute labels public function attributeLabels() { return [ 'id' => 'Post ID', 'title' => 'Post Title', 'content' => 'Post Content', ]; } } // Create a model instance $post = new Post(); // Get the label for the title attribute $label = $post->getAttributeLabel('title'); echo $label; // Output: "Post Title"In the above example, we define a model class called "Post" with three attributes: id, title, and content. We also define the attribute labels using the attributeLabels() method. We then create an instance of the Post model and use the getAttributeLabel() method to get the label for the "title" attribute. This code is part of the Yii Base package library.
public getAttributeLabel ( string $attribute ) : string | ||
$attribute | string | the attribute name |
return | string | the attribute label |