如何在 YII2 ActiveController 中按降序返回数据?请帮我。从 activecontroller 返回的 JSON 响应必须按 news_id 降序排列。
<?php
namespace app\api\modules\v1\controllers;
use yii\web\Response;
use yii\rest\ActiveController;
class NewsController extends ActiveController {
// We are using the regular web app modules:
public $modelClass = 'app\models\News';
}
这是新闻模型
<?php
namespace app\models;
use Yii;
class News extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'news';
}
public function rules()
{
return [
[['news_title', 'news_description', 'news_link'], 'required'],
[['news_description', 'news_link'], 'string'],
[['news_time'], 'safe'],
[['news_title'], 'string', 'max' => 255],
];
}
public function attributeLabels()
{
return [
'news_id' => 'News ID',
'news_title' => 'News Title',
'news_description' => 'News Description',
'news_link' => 'News Link',
'news_time' => 'News Time',
];
}
}