Multi Value Field In Cgridview

hi Guys

I’m new to Yii so I need a little help

I’m using Cgrid view I handle CChecBoxCol and ClinkCol well

but one of the field of the model is an array

how do u guys handle similar situations

Is ther is a way to use DropdownList in the grid view jut for display the array values

plz help

Hi diaa, welcome to the forum.

I don’t understand what you mean by that.

Is the field(attribute) an array? Or, does it take a value in some array?

And is it related to other model?

Would you please explain your question with some sample data?

it is a related to other model

e.g. model Class , model Students (Class HasMany Students ) relation

I want to display ‘Class’ model in CgridView (all classes) with on of the columns is studentsNames as a dropdown for example or any other way u find it more confient

I see.

The most simple solution should be like this:

// in Class.php

/* returns the students' names joined by \n */

public function getStudentNames()


    $names = array();

    foreach($this->students as $student) {

        $names[] = $student->name;


    return implode("\n", $names);


// in View

$this->widget('zii.widgets.grid.CGridView', array(

    'id' => 'class-grid',

    'dataProvider' => $model->search(),

    'filter' => $model,

    'columns' => array(



            'name' => '',

            'type' => 'ntext',

            'value' => '$data->studentNames',



Probably you already know that, and don’t like the row to be very tall with many sutudents’ names …

There should be many other ways to display the related HAS_MANY model objects. I don’t think there’s a standard way for doing it.

Well, but I don’t think it’s a good idea to use dropDownList just for displaying data. It should be confusing to the users, because the dropDownList is expected to be an input element.

I hope this wiki will be a good hint.