Change sequence of column in yii framework (CActiveRecords)

203 Views Asked by At

The output grid has following sequence of columns of a table -> B, C, D, E, A (same sequence as in table in database). But I need this sequence of columns -> A, B, C, D, E. I know how to do this using sql query. But I have to do this in Yii framework(I am very new to Yii framework).

This is my code for MyClass which extends CActiveRecords

class Myclass extends CActiveRecord
{  
public function tableName()
{
    return 'dbName.dbTableName';
}
public function rules()
{
    //Some rules
}
public function relations()
{
    //Some modified relations
}
public function attributeLabels()
{
    return array(
        'a' => 'A',
        'b' => 'B',
        'c' => 'C',
        'd' => 'D',
        'e' => 'E',
    );
}
public function search()
{

    $criteria=new CDbCriteria;

    $criteria->compare('a',$this->A);
    $criteria->compare('b',$this->B);
    $criteria->compare('c',$this->C,true);
    $criteria->compare('d',$this->D,true);
    $criteria->compare('e',$this->E,true);
    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}
public function getDbConnection()
{
    return Yii::app()->db1;
}
public static function model($className=__CLASS__)
{
    return parent::model($className);
}
}

1) Is there any inbuilt function in Yii Framework which can re-arrange the sequence of columns of according to my needs.

2) I should re-arrange the columns sequence here or somewhere else. I mean is this the right class for re-arranging column sequence.

3) Can anyone suggest me some good tutorial for advance Yii framework ( Video Tutorial, if possible).

Thanks a lot for the help

1

There are 1 best solutions below

0
On BEST ANSWER
  1. Yes. Add this:

    $criteria->select = 'a, b, c, d, e'; // columns in the desired sequence

  2. If you always want this sequence when using the search() method, this is the right place.

  3. Sorry, can't really help you here. Learn to read the Yii Framework documents and you can almost find everything you need.