spy-enot
spy-enot

Reputation: 203

Yii model sorting

How can I sort by PK in this case?

$model=new SupportTicket('search');

I can do that using search method inside the model, but I have to do that with object. Sure I can rewrite standard method using DbCriteria, but probably easy way exists?

Upvotes: 1

Views: 1045

Answers (3)

Sorin P
Sorin P

Reputation: 36

You can use sort in your in search() model:

return new CActiveDataProvider($this, array(
    'criteria' => $criteria,
    'sort' => array('defaultOrder' => 'id DESC'),
));

Upvotes: 0

jonazu
jonazu

Reputation: 380

I always use the find methods provided by CActiveRecord:

$model = SupportTicket::model()->findAll(array('order'=>'PK'));

Upvotes: 1

Daniel Vaquero
Daniel Vaquero

Reputation: 1305

On 'search()' method, you can put:

    $criteria=new CDbCriteria;
    $criteria->order = 'id ASC';

    return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
            ));

Upvotes: 1

Related Questions