Concate String In Chtml::listdata

I have table with following fields :





Here is my data :

1 7005 Ravi CE

2 7006 Parth CE

3 7007 Yashpal IT

4 7008 Sukunj IT

I want to display data in dropdown with following format




Sukunj-7008(IT) using CHtml::listData

Here is my view file code


echo CHtml::dropDownList('stud_id', '',CHtml::listData(Student::model()-&gt;findAll(), 'id', 'concate')

); ?>

Here is my model file’s concate method

public function getConcate()


    return &#036;this-&gt;name.&quot;-&quot;.&#036;this-&gt;roll_no.&quot;(&quot;.&#036;this-&gt;branch.&quot;)&quot;;

// or whatever format you want to display


By create this type of method you can concate any type of string that you need.

Here is the output.

I had the same problem, which solve by create a function (return the concatenated list) USING sql and pass to array Which fine and works for like in function:


$sql=‘Your query’;



        &#036;aAry = array();

       foreach(&#036;rows as &#036;row){

           &#036;aAry [&#036;row['id']] = &#036;row['name1'].' | '.&#036;row['name2'].' | '.&#036;row['name3'];







in view…

and list echo $form->dropDownListRow($model, ‘myfield’,$$aAry,array(‘class’=>‘span7’));

this is works for

Thankx for code…

But you need to require loop for making your required string/array. In my case this is not required.

[color="#006400"] /* moved from Feature Requests */[/color]