CommentsController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace control\controllers;
  3. use control\models\CommentsSearch;
  4. use \app\models\base\Comments;
  5. use yii\data\ActiveDataProvider;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. /**
  10. * CommentsController implements the CRUD actions for Comments model.
  11. */
  12. class CommentsController extends BaseController
  13. {
  14. /**
  15. * @inheritDoc
  16. */
  17. public function behaviors()
  18. {
  19. return array_merge(
  20. parent::behaviors(),
  21. [
  22. 'verbs' => [
  23. 'class' => VerbFilter::className(),
  24. 'actions' => [
  25. 'delete' => ['POST'],
  26. ],
  27. ],
  28. ]
  29. );
  30. }
  31. /**
  32. * Lists all Comments models.
  33. *
  34. * @return string
  35. */
  36. public function actionIndex()
  37. {
  38. $searchModel = new CommentsSearch();
  39. $dataProvider = $searchModel->search(\Yii::$app->request->get());
  40. return $this->render('index', [
  41. 'dataProvider' => $dataProvider,
  42. 'searchModel' => $searchModel,
  43. ]);
  44. }
  45. /**
  46. * Displays a single Comments model.
  47. * @param int $id
  48. * @return string
  49. * @throws NotFoundHttpException if the model cannot be found
  50. */
  51. public function actionView($id)
  52. {
  53. return $this->render('view', [
  54. 'model' => $this->findModel($id),
  55. ]);
  56. }
  57. /**
  58. * Lists all Comments models.
  59. *
  60. * @return string
  61. */
  62. public function actionRss()
  63. {
  64. $model = new Comments();
  65. $dataProvider = new \yii\data\ActiveDataProvider(
  66. [
  67. "query"=>$model->find(),
  68. "pagination" =>[
  69. "pageSize"=>200
  70. ],
  71. 'sort' => [
  72. 'defaultOrder' => [
  73. 'created_at' => SORT_DESC,
  74. ]
  75. ],
  76. ]);
  77. return $this->renderPartial('rss', [
  78. 'dataProvider' => $dataProvider,
  79. ]);
  80. }
  81. /**
  82. * Finds the Comments model based on its primary key value.
  83. * If the model is not found, a 404 HTTP exception will be thrown.
  84. * @param int $id
  85. * @return Comments the loaded model
  86. * @throws NotFoundHttpException if the model cannot be found
  87. */
  88. protected function findModel($id)
  89. {
  90. if (($model = CommentsSearch::findOne(['id' => $id])) !== null) {
  91. return $model;
  92. }
  93. throw new NotFoundHttpException('The requested page does not exist.');
  94. }
  95. }