コード例 #1
0
 public function actionIndex()
 {
     $query = Article::find();
     $channelId = $this->getQuery('channel');
     $where = ['isDeleted' => false, 'channel' => new \MongoId($channelId)];
     $orderBy = $this->getQuery('orderBy');
     if (!empty($orderBy)) {
         $orderBy = Json::decode($orderBy, true);
         foreach ($orderBy as $key => $value) {
             if ('asc' === strtolower($value)) {
                 $orderBy[$key] = SORT_ASC;
             } else {
                 $orderBy[$key] = SORT_DESC;
             }
         }
     } else {
         $orderBy = ['createdAt' => SORT_DESC];
     }
     return new ActiveDataProvider(['query' => $query->where($where)->orderBy($orderBy)]);
 }