Reputation: 360
In my DB there is a column call status
with four type of data NEW, RESUBMITTED, APPROVE and REJECT.
I have successfully "ORDER BY DESC" of the status
to VIEW. However, what I really want is the status
can list by :
Currently for the "ORDER BY DESC" is:
In Model I added this code for ORDER:
public function scopes() {
return array(
'bystatus' => array('order' => 'status DESC'),
);
}
In Controller action:
public function actionAppListPage()
{
$count = '0';
$id = Yii::app()->user->getState('id');
$models = Developers::model()->bystatus()->findAll('developer_id='.$id);
$this->render('applist',array('models'=>$models,'count'=>$count));
}
Screenshot
How to order the status I want ? Or any other suggestion to do that? Thanks
Upvotes: 0
Views: 59
Reputation: 1041
You should define your order like :
public function scopes() {
return array(
'bystatus' => array(
'order' => "(CASE status WHEN 'REJ' THEN 0 WHEN 'APPROVE' THEN 1 WHEN 'RESUBMITTED' THEN 2 WHEN 'NEW' THEN 3 ELSE 4 END)",
)
);
}
Upvotes: 1