Cgridview With Data From Two Tables

Two tables BillDetails and Attachments. Each entry in BillDetails may have multiple attachments. I need to display the BillDetails data with Attachments as link in a gridview. That is the gridview need to have columns Amount, Description and Attachments.

Am new to php and yii…

In gridview call the model function





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

	'id'=>'downloadlog-grid',

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


	'columns'=>array(

		'amount',

		'description',

		array(

            'header'=>'Attachment',

            'value'=>'$data->attachmentlink()',

        ),

	),

)); ?>

model will check the current record with relation table and display the attachment link




<?php

	public function attachmentlink(){

		//$this->attachment is a relation name

		if($this->attachment){ 

			echo "<ul>";

			foreach($this->attachment as $attachment){

				echo "<li><a href=".$attachment->path.">".$attachment->name."</a></li>";

			}

			echo "</ul>";

		}else

			echo "No Attachments";

	}

?>



Thank you… This worked for me…