今天做一个功能,我有一个表,是寄存系统所有公司的信息,但是公司的类别更加type这个字段把公司分为一般公司名字和重要公司名字,但2个都是保存到companyName这个字段下面。yii的attributeLabels很方便可以做到那个输入字段的提示文字。现在问题来了,如何让它在同一个model里面显示不同的labels名字呢。
直接贴代码。
/** implementation */
private $_currentLabelCollection = null;
public function getCurrentLabelCollection() {
return $this->_currentLabelCollection;
}
public function setCurrentLabelCollection($value) {
if(!$value || array_key_exists($value, $this->_attributeLabelCollections)) {
$this->_currentLabelCollection = $value;
} else {
throw new CException(Yii::t("error", "Model {model} does not have a label collection named {key}.", array(
'{model}' => get_class($this),
'{key}' => $value,
)));
}
}
private $_attributeLabelCollections = array(
'collection1' => array(
'line_