attributeLabels() public method

Attribute labels are mainly used for display purpose. For example, given an attribute firstName, we can declare a label First Name which is more user-friendly and can be displayed to end users. By default an attribute label is generated using Model::generateAttributeLabel. This method allows you to explicitly specify attribute labels. Note, in order to inherit labels defined in the parent class, a child class needs to merge the parent labels with child labels using functions such as array_merge().
See also: generateAttributeLabel()
public attributeLabels ( ) : array
return array attribute labels (name => label)
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     $labels = parent::attributeLabels();
     $labels['name'] = Yii::t('app', 'Name');
     $labels['email'] = Yii::t('app', 'Email');
     $labels['subject'] = Yii::t('app', 'Subject');
     $labels['body'] = Yii::t('app', 'Body');
     $labels['verifyCode'] = Yii::t('app', 'Verification Code');
     return $labels;
 }
 /**
  * @inheritDoc
  */
 public function attributeLabels()
 {
     return ArrayHelper::merge(parent::attributeLabels(), ['url' => 'URL']);
 }
Example #3
0
 public function attributeLabels()
 {
     return array_merge(parent::attributeLabels(), ['name' => \Yii::t('app', 'Name'), 'version' => \Yii::t('app', 'Installed version'), 'alias' => \Yii::t('app', 'Aliases')]);
 }
 /**
  * @inheritDoc
  */
 public function attributeLabels()
 {
     return ArrayHelper::merge(parent::attributeLabels(), ['attribute' => 'Атрибут']);
 }
Example #5
0
 public function testDefaults()
 {
     $singer = new Model();
     $this->assertEquals([], $singer->rules());
     $this->assertEquals([], $singer->attributeLabels());
 }
Example #6
0
 public function attributeLabels()
 {
     return \yii\helpers\ArrayHelper::merge(parent::attributeLabels(), ['username' => 'email']);
 }
Example #7
0
 public function attributeLabels()
 {
     $labels = ['username' => '用户名', 'email' => '邮箱', 'password' => '密码', 'confirmPassword' => '确认密码', 'verifyCode' => '验证码'];
     return array_merge(parent::attributeLabels(), $labels);
 }
Example #8
0
 /**
  * @return array customized attribute labels
  */
 public function attributeLabels()
 {
     return array_merge(parent::attributeLabels(), ['verifyCode' => Yii::t('app', 'Verification Code')]);
 }
Example #9
0
 public function attributeLabels()
 {
     $labels = ['username' => '用户名', 'password' => '密码', 'rememberMe' => '记住我'];
     return array_merge(parent::attributeLabels(), $labels);
 }