[SOLVED]get attribute labels staticlly

hi there

how can i get attribute label statically from a model

i dont want to create a static function similar to attributeLabels, because by any change in attributeLabels function, i have to do the same in static one

thanks in advanced

Hi,

I think I don’t understand what exactly your question is.

Could you explain a little bit more what you try to achieve?

Regards

thanks for your spending time

imagine i have this in my model:




    public function attributeLabels()

    {

        return [

            'id' => 'ID',

            'title' => 'عنوان',

            'department_id' => 'دپارتمان',

            'cover' => 'کاور',

        ];

    }



i want to get one o these attribute’s label statically in my view. For now im using this to reach my purpose:




    public static function label(){

        return (new SubDepartment)->attributeLabels();

    }



and for ex in my veiw:




<?= ModelName::label()['title'] ?>



Does Yii has a self defined method to doing the same thing that I did in above?

thanks in advanced.

no. this methods are not static.

you may extend ActiveRecord.

yeah, good idea, thanks

i added the following in yii\db\ActiveRecord but not worked:




public static function labels(){

    return (new ActiveRecord())->attributeLabels();

}