Click here for EduSec Demo EduSec Screenshots

Concate String in CHtml::listData

On 2013-06-10 - By Ravi Bhalodiya

I have table with following fields :
id
roll_no
name
branch

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
Ravi-7005(CE)
Parth-7006(CE)
Yashpal-7007(IT)
Sukunj-7008(IT)     using CHtml::listData

Here is my view file code
<?php
    echo CHtml::dropDownList('stud_id', '',CHtml::listData(Student::model()->findAll(), 'id', 'concate')
); ?>

Here is my model file's concate method

    public function getConcate()
    {
        return $this->name."-".$this->roll_no."(".$this->branch.")";
// or whatever format you want to display
    }