Model::order
Set Order Parameter
Description
public self Model::order( string $order, [ string $duration = 'ASC' ] )
Adds a column to ORDER BY. Call it again for a second sort key.
$ordermust be a column name (post_dateorcms_news.post_date); anything else, such as'post_date desc'or an expression, throwsInvalidArgumentException. Use orderRaw for expressions.$durationisDESC(case-insensitive) or anything else forASC, so it is safe to pass a sort direction from the request.order('random')sorts in random order (ORDER BY RANDOM(), an SQLite function).
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $order | string | Column name, or 'random' | |
| $duration | string | 'ASC' | 'ASC' or 'DESC' |
Example
Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
// ... Order By post_date DESC,news_id DESC
$records = $model->order('post_date', 'desc')->order('news_id', 'desc')->find();
// 3 random news
$records = $model->order('random')->limit(3)->all();