如何获得yii中的所有属性标签


How to get all atrribute labels in yii 1

我有Brand表(它包含brand_id, brand_name, b_year)和以下代码

`Products::model()->getAttributeLabel('brand_id')` 
var_dump(Products::model()->getAttributeLabel('brand_id'));

只显示brand_id标签。我怎样才能显示所有的标签而不是一个?

试试这个

var_dump(Products::model()->attributeLabels());

attributeLabels()Model中的function。它返回一个array, database字段作为键。

要获取所有标签你只需要调用不带参数的

var_dump(Products::model()->attributeLabels()); // this will return complete array

由于getAttributeLabel写在CActiveRecord中,并且根据定义它期望和参数,它不会给出所有字段标签

请尝试一下,

$lables = Products::model()->attributeLabels();
print_r($labels);

$lables返回Products模型中的所有标签。