Concate String in CHtml::listData

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
    }

By create this type of method you can concate any type of string that you need.
Here is the output.

Image

Advertisements

2 comments

  1. site link · February 25, 2014

    Good post. I learn something totally new and challenging on websites I stumbleupon everyday.
    It will always be interesting to read through content from other authors and practice something from their websites.

  2. Hi there all, here every person is sharing such know-how, so it’s fastidious
    to read this weblog, and I used to go to see this blog every day.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s