Reputation: 203
What is the best way to display 1 as "Yes" and 0 as "No" on View and listing pages which use Yii generated CRUD code (zii.widgets.CDetailView
).
I'm writing down below simply which worked for me if it helps others (Thanks to Pentium 10 for the hint):
$this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
's_no',
'gateway',
'code',
'isvlid',
),
));
$this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
's_no',
'gateway',
'code',
// Is Valid (Now i control the Label and Display Value)
array(
'label'=>'Active',
'value'=>$model->isvalid ? "Yes" : "No",
),
),
));
Upvotes: 1
Views: 1351
Reputation: 207902
I have this a CGridView, it might help you:
array(
'name' => 'isregistered',
'header' => "Reg.?",
'value' => '$data->isregistered?Yii::t(\'app\',\'Yes\'):Yii::t(\'app\', \'No\')',
'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),
'htmlOptions' => array('style' => "text-align:center;"),
),
Upvotes: 2