[SOLVED] CGridView image column rare error


Yii 1.1.15

Windows 7 Professional SP1 64-bit

XAMPP Server 1.8.3

Apache 2.4 ,

PHP 5.5.15


Hi, i’m trying to add a image on a grid column

I recive this error on the column, the rest of the page renders well.

[color="#FF0000"]Parse error: syntax error, unexpected ‘<’ in X:\www_dev\yii\framework\base\CComponent.php(612) : eval()'d code on line 1[/color]

this is my view (grid part)




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

	'id'=>'user-grid',

	'itemsCssClass'=>'table table-hover table-striped table-bordered table-condensed',

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

	'filter'=>$model,

	'columns'=>array(

		'username',

		'email',

		'firstname',

		'lastname',

		'created',

		'lastvisit',

        array(

            'name' => 'active',

            'type' => 'html',

            'value' => CHtml::image(UtilityHTML::getStatusImage(1),UtilityHTML::getImagetitle(1),array('width'=>50, 'height'=>50))

        ),

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>

this is a component to get image by status


<?php


class UtilityHTML

{


    public static function getImagetitle($status) {

        if ($status == 1) {

            return 'Active';

        } else {

            return 'Inactive';

        }

    }


    public static function getStatusImage($status) {

        if ($status == 1) {

            return Yii::app()->request->baseUrl . '/images/ui/status_1.png';

        } else {

            return Yii::app()->request->baseUrl . '/images/ui/status_0.png';

        }

    }


}

Thank you

Pablo

Try like this -


CHtml::image(Yii::app()->utilityHTML->getStatusImage(1),'', array('style'=>'width:50px; height:50px'));

Need to set in your config (main.php) -


'components'=>array(

   'utilityHTML' => array(

            'class' => 'application.components.UtilityHTML',

        ),

 )

wrap the value in quotes like so

‘value’ => “CHtml::image(UtilityHTML::getStatusImage(1),UtilityHTML::getImagetitle(1),array(‘width’=>50, ‘height’=>50))”

This option not worked, but thanks anyway.

this solves the problem, Thank you alirz23