In an admin view I want to be able to show the Status as text rather than as the value which is stored in the database. For Status I have Created (0), In Progress (1) and Completed (2). Instead of showing 0,1, or 2 in the admin view, I want to show Created, In Progress etc.
In the Model I have the following
const STATUS_CREATED=0;
const STATUS_PROGRESS=1;
const STATUS_COMPLETED=2;
public function getActiveStatus()
{
return array(
self::STATUS_CREATED=>'Created',
self::STATUS_PROGRESS=>'In Progress',
self::STATUS_COMPLETED=>'Completed',
);
}
public function getActiveStatusText ()
{
$activeStatus=$this->getActiveStatus();
return isset($activeStatus[$this->status]) ? $activeStatus[$this->status] : "unkown status({$this->status})";
}
I use TbDetailView in another view and I can show the corresponding text by using
<?php $this->widget('bootstrap.widgets.TbDetailView', array(
'type'=>'striped bordered condensed',
'data'=>$model,
'attributes'=>array(
'client.business_name',
'user.real_name',
'file_name',
array(
'name'=>'import_date',
'value'=>date("d-m-Y",strtotime($model->import_date)),
),
array(
'name'=>'status',
'value'=>CHtml::encode($model->getActiveStatusText()),
),
),
However when I try to use this in my admin view I get errors.
<?php $this->widget('bootstrap.widgets.TbGridView', array(
'type'=>'striped bordered condensed',
'id'=>'new-task-grid',
'template'=>"{items}",
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'client.business_name',
'user.real_name',
/*'import_id',
'export_id',*/
'file_name',
/*
'import_date',*/
array(
'name'=>'status',
'filter'=>$model->getActiveStatus(),
),
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'htmlOptions'=>array('style'=>'width: 50px'),
),
),
In this last code snippet how can I show the Text for Status rather than 0,1,2 (note - The filter for Status works fine_ however what is the syntax that I require to use value e.g.
array(
'name'=>'status',
'filter'=>$model->getActiveStatus(),
'value'=>CHtml::encode($model->getActiveStatusText()),
),
Using the last code snippet I get “Parse error: syntax error, unexpected ‘status’ (T_STRING)…”
Essentially in admin view I want to show the Text ->Created, In Progress rather than 0 or 1.