Cgridview Value


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

	'id'=>'blog-grid',

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

	'filter'=>$model,

	'columns'=>array(

		'id',

		'title',

		'date',

		'published',

		array(

              'name'=>'published',

			  'type' => 'raw',

              'value'=>'($model->published == 1) ? "yes" : "no"',

              ),

		'info',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>

Can someone shed some light on why this condition ain’t working, the condition never meets. I tried with other attributes but it always chooses the not true.

I tried to put quotes on "1", single, double, I tried with !==1 which prints yes for everything, while ==1 prints no.

Outside Cgridview it’s all good, works fine.

Thanks

There’s an error in your syntax, but I can’t tell if it’s just a typo in copying your code to the forum. You have this as your value:


('$model->published == 1) ? "yes" : "no"',)

I’m assuming that you need an additional opening bracket within the first quote.

try this…!!


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

     'id'=>'blog-grid',

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

     'filter'=>$model,

     'columns'=>array(

         array(

           'name'=>'published',

           'type' => 'raw',

           'value'=>function($data){

                 return '($model->published == 1) ? "yes" : "no"',;

         }),

       ),

)); 

your code is:




'value'=>('$model->published == 1) ? "yes" : "no"',



but it should be:




'value'=>'($model->published == 1) ? "yes" : "no"',



or creat a function in your model and run it here:




'value'=>'$model->change_status($model->published)',



Guys thanks for the help, but still no luck, I tried making a method in my model. The quote thing is a mistake while uploading it here (changed it). I tried all the solutions posted. The only new info I have come across is that it actually takes the value of the 1st row and just uses it for the rest. However this ‘value’=>$model->published, displays correctly.


array(

           'name'=>'published',

           'type' => 'raw',

		    'value'=>$model->changeP($model->published),

		   ),

model




public function changeP($state){

	if ($state == 0){

	$state = 'yes';

	}else{

		$state = 'no';


	}

	return $state;

	

	}

If I use quotes




'value'=>'$model->changeP($model->published)',

I get this error

Thanks

I think you should be using $data instead of $model.