TheSmile
TheSmile

Reputation: 360

Yii ORDER column data in view

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 :

  1. REJECT
  2. APPROVE
  3. RESUBMITTED
  4. NEW

Currently for the "ORDER BY DESC" is:

  1. RESUBMITTED
  2. REJECT
  3. NEW
  4. APPROVE

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

enter image description here

How to order the status I want ? Or any other suggestion to do that? Thanks

Upvotes: 0

Views: 59

Answers (1)

turutosiya
turutosiya

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

Related Questions