我有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
模型中的所有标签。