Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Expression in value of CGridView not working as expected

$
0
0
I am using a ternary operator as an expression in the value as seen in my view's code below:

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'trip-grid',
	'dataProvider'=>$dataProvider,
	// 'filter'=>$model,
	'columns'=>array(
    array(  'name'=>'f_user_admin',
						'header'=>'Admin?',
						'value'=>$data->f_user_admin,
        ),
    array(  'name'=>'f_user_admin',
						'header'=>'Admin?',
						'value'=>(($data->f_user_admin == 1) ? "Yes" : "No"),
        ),
		array(
			'class'=>'CButtonColumn',
        'viewButtonUrl'=>'Yii::app()->controller->createUrl("view",$data->primaryKey)',
        'updateButtonUrl'=>'Yii::app()->controller->createUrl("update",$data->primaryKey)',
        'deleteButtonUrl'=>'Yii::app()->controller->createUrl("delete",$data->primaryKey)',			
		),
	),
)); ?>


f_user_admin is a TINYINT(4) field in my mySQL database. The table has three records. f_user_admin has a value of 1 for the first record and a value of 2 for the other two records.

If you look at the attached image, you'll see that the first column displays the correct values from the database. The seconds column should display "Yes" for a value of 1, and "No" for a value of 0. However, as you can see by the image, it always displays "No".

Am I missing something?

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>