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
Page 1 of 1
Modify Drop Down List
#1
Posted 06 December 2012 - 08:49 PM
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
#2
Posted 06 December 2012 - 11:18 PM
Try this way,
In controller, create an array
then in view,
you also can write a function in Model and use it as below,
I havent tested the second way, so let me know if you get it work.
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.
#3
Posted 08 December 2012 - 03:24 AM
I would use virtual attribute in this case (though there may be some other solutions).
For example, in your model
and then use this data in your activeDropDownList
Beauty
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
#4
Posted 09 December 2012 - 10:46 PM
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
I modified my codes like yugene's codes, and yes, it's work !
thank you very much anyway
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
Share this topic:
Page 1 of 1

Help















