CarouselController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 莫名疯
  5. * DateTime: 2017/3/8 10:09
  6. * Description:
  7. */
  8. namespace api\modules\v1\controllers;
  9. use api\common\controllers\Controller;
  10. use api\common\models\CarouselItem;
  11. use common\models\Carousel;
  12. use yii\data\ActiveDataProvider;
  13. class CarouselController extends Controller {
  14. /**
  15. * @api {get} /v1/carousels 列表
  16. * @apiVersion 1.0.0
  17. * @apiName index
  18. * @apiGroup Carousel
  19. *
  20. *
  21. */
  22. public function actionIndex($key = 'index') {
  23. $data = new ActiveDataProvider([
  24. 'query' => CarouselItem::find()
  25. ->joinWith('carousel')
  26. ->where([
  27. '{{%carousel_item}}.status' => CarouselItem::STATUS_ACTIVE,
  28. '{{%carousel}}.status' => Carousel::STATUS_ACTIVE,
  29. '{{%carousel}}.key' => $key,
  30. ])
  31. ->limit(10),
  32. 'pagination' => false,
  33. 'sort' => [
  34. 'defaultOrder' => [
  35. 'sort' => SORT_ASC
  36. ]
  37. ],
  38. ]);
  39. return $data;
  40. }
  41. }