CommentController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 2017/3/8
  6. * Time: 下午11:19
  7. */
  8. namespace api\modules\v1\controllers;
  9. use api\common\controllers\Controller;
  10. use api\modules\v1\models\Comment;
  11. use common\enums\StatusEnum;
  12. use yii\data\ActiveDataProvider;
  13. use yii\web\ServerErrorHttpException;
  14. class CommentController extends Controller
  15. {
  16. /**
  17. *
  18. * @param $entity
  19. * @param $entity_id
  20. * @return ActiveDataProvider
  21. * @throws ServerErrorHttpException
  22. * @author nodelog
  23. */
  24. public function actionIndex($entity, $entity_id)
  25. {
  26. $entityList = \common\models\Comment::getEntityList();
  27. if (!isset($entityList[$entity])) {
  28. throw new ServerErrorHttpException('空空如也');
  29. }
  30. $query = Comment::find()->where(['entity' => $entity, 'entity_id' => $entity_id, 'status' => StatusEnum::STATUS_ON, 'parent_id' => 0]);
  31. return new ActiveDataProvider([
  32. 'query' => $query,
  33. 'pagination' => [
  34. 'pageSize' => Comment::PAGE_SIZE,
  35. ],
  36. 'sort' => [
  37. 'defaultOrder' => [
  38. 'created_at' => SORT_ASC,
  39. ]
  40. ]
  41. ]);
  42. }
  43. }