CGridView with multiple images per column

Hello people,

I have a CGridView grid and I need to show four images in one cell, based on row data.

Is it possible?



Hm… Seems to be very interesting topic for today, as exactly three hours before you (on 06:07 AM) somebody else has asked exactly (or nearly exactly) the same question. Take a look at my answer to him.

In general: It is possible to display one or many images in CGridView, but as more experienced users stated often for complex purposes like this it is worth considering using CListView, where each row is generated basing on provided view file so it thousand times more flexible and lets you do virtually anything.


and thanks Trejder!

I eventually choose to build a mash-up with CGridView/CButtonColumn.

The solution for others, on the view/<…>.php script:

 	$columns = array();

	$columns[] = 'field1';

	$columns[] = 'field2';

	$columns[] = array(

                'class' => 'CButtonColumn',

                'template' => '{button1} {button2} {button3}',

                'header' => 'Status',

                'htmlOptions' => array('style' => 'text-align: center;', 'nowrap' => '' ),

                'buttons' => array(

                    'button1' => array(

                        'label' => 'Ra material',

                        'imageUrl' => Yii::app()->baseUrl . '/images/image1.png',

                        'visible' => 'True',


                    'button2' => array(

                        'label' => 'Cassiopaea experiment',

                        'imageUrl' => Yii::app()->baseUrl . '/images/image2.png',

                        'visible' => 'True',


                    'button3' => array(

                        'label' => 'Pleiadians transcriptions',

                        'imageUrl' => Yii::app()->baseUrl . '/images/image3.png',

                        'visible' => 'True',




 	$columns[] = 'more_fields';

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


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

		'filter'=> $model,

		'columns' => $columns