so I have this table :
CREATE TABLE KBCATEGORY
(
CATEGORYID
int(11) NOT NULL auto_increment,
CATEGORYNAME
varchar(100) NOT NULL,
ISPRIVATE
tinyint(1) NOT NULL,
CATEGORYUPID
int(11) NOT NULL,
CATORDER
int(11) NOT NULL,
KBCOUNT
int(11) NOT NULL,
PRIMARY KEY (CATEGORYID
)
how to modify a dropdownlist, so it will show not only the CATEGORYNAME but also the KBCOUNT?
So, it will appears like : CATEGORYNAME (KBCOUNT) or for example, Knowledge Base (12)
thanks for helping
mazraara
(Mazraara)
2
Try this way,
In controller, create an array
$values = array(
0 => array('id' => "1", "name" => CATEGORYNAME . KBCOUNT),
1 => array('id' => "2", "name" => CATEGORYNAME . KBCOUNT ),
);
then in view,
echo CHtml::activeDropDownList($model, 'attr', CHtml::listData($values, 'id', 'name'));
you also can write a function in Model and use it as below,
echo CHtml::activeDropDownList($model, 'attr', CHtml::listData($model->functionName(), 'id', 'name'));
I havent tested the second way, so let me know if you get it work.
yugenekr
(Yugenekr)
3
I would use virtual attribute in this case (though there may be some other solutions).
For example, in your model
public function getMyCusomName(){
return $this->categoryname.' ('.$this->kbcount.')';
}
and then use this data in your activeDropDownList
CHtml::listData(Kbcategory::model()->findAll(), 'id', 'myCustomName');
Beauty 
hi all, thanks for your answer. actually, I’ve done this before you people help me out 
I modified my codes like yugene’s codes, and yes, it’s work ! 
thank you very much anyway 