Cgridview Image Entry

Hi,

I am trying to place icons in my CGridView to represent boolean data.

I have added a function in User model to do the boolean check and echo out the icon result. The code can be found as below


 //CHANGE BOOLEAN IMAGE TO TICK/CROSS

	public function booImage($check)

	{

		$check=Yii::app()->format->formatNumber($check);

		if ($check==0)

				echo "<img src=/www/images/cross.gif>";

				else echo "<img src=/www/images/bluetick.jpg>";

	}  

	

Also the View.php of the User model is as follows


<h1>View User : <?php echo $model->username; ?></h1>


<?php 


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

	'data'=>$model,

	'attributes'=>array(

		'ID',

		'username',

		'firstname',

		'lastname',

		'country',

		'position',

		array(

			'name'=>'request_permit',

			'data'=>User::booImage($model->request_permit),

			),

			

			array(

			'name'=>'view_permit',

			'data'=>User::booImage($model->view_permit),

			),


		

			)

I am however getting the following result.

Is this a CSS related issue?

Thanks in advance

Hi m3rc, welcome to the forum.

Don’t echo the img tag, but return it as a string.

And you’d be better quote ‘src’ attribute of ‘img’ tag.




	return "<img src='/www/images/cross.gif'>";

	else return "<img src='/www/images/bluetick.jpg'>";



And it’s not ‘data’ but ‘value’. And you have to set ‘type’ to ‘raw’.




	array(

		'name'=>'request_permit',

		'type'=>'raw',

		'value'=>User::booImage($model->request_permit),

	),

	array(

		'name'=>'view_permit',

		'type'=>'raw',

		'value'=>User::booImage($model->view_permit),

	),



hey thanks! cheers!!! :D