Showing different value instead of values returned form column

I am using a dataprovider and getting data as per some condition


$dataProvider=new CActiveDataProvider('Contacts' ,array('criteria'=>array(

        'condition'=>'status=1 AND id='.$id,)));

Now in my view I will get this data as


$data->status

which gives me 1 or 2 or 3 or 4 or 5 or…

Now I don’t want to show 1, 2, 3… instead I would like to show active instead of 1, inactive for 2, disabled for 3…

How will I achieve this?

You can pass $data->status to a function and then return the appropriate display value.




// model code

...

public function getStatuses()

{

    return array(

        1 => 'Active',

        2 => 'Inactive',

        3 => 'Disabled',

    );

}

public function getChoosenStatus($status)

{

    $statuses = $this->getStatuses();

    return $statuses[$status];

}

...

// view code

...

echo $model->getChoosenStatus($data->status);

...



That’s all.