Yii Framework Forum: Modify Drop Down List - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Modify Drop Down List Rate Topic: -----

#1 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 06 December 2012 - 08:49 PM

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
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#2 User is offline   Azy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 154
  • Joined: 16-May 12

Posted 06 December 2012 - 11:18 PM

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.
0

#3 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 488
  • Joined: 08-August 09
  • Location:World is Wide

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
public function getMyCusomName(){
 return $this->categoryname.' ('.$this->kbcount.')';
}

and then use this data in your activeDropDownList
CHtml::listData(Kbcategory::model()->findAll(), 'id', 'myCustomName');


Beauty :)
0

#4 User is offline   dyooolicious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 18-October 12
  • Location:Surabaya, East Java, Indonesia

Posted 09 December 2012 - 10:46 PM

hi all, thanks for your answer. actually, I've done this before you people help me out :P
I modified my codes like yugene's codes, and yes, it's work ! :D
thank you very much anyway ;D
keep learning, trying and praying makes you keep going !
tweet me : @dyooolicious
http://ini-infonya.blogspot.com/
0

#5 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 488
  • Joined: 08-August 09
  • Location:World is Wide

Posted 09 December 2012 - 11:48 PM

welcome ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users