123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace control\controllers;
- use control\models\CommentsSearch;
- use \app\models\base\Comments;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- class CommentsController extends BaseController
- {
-
- public function behaviors()
- {
- return array_merge(
- parent::behaviors(),
- [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ]
- );
- }
-
- public function actionIndex()
- {
- $searchModel = new CommentsSearch();
- $dataProvider = $searchModel->search(\Yii::$app->request->get());
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- 'searchModel' => $searchModel,
- ]);
- }
-
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
-
- public function actionRss()
- {
- $model = new Comments();
- $dataProvider = new \yii\data\ActiveDataProvider(
- [
- "query"=>$model->find(),
- "pagination" =>[
- "pageSize"=>200
- ],
- 'sort' => [
- 'defaultOrder' => [
- 'created_at' => SORT_DESC,
- ]
- ],
- ]);
- return $this->renderPartial('rss', [
- 'dataProvider' => $dataProvider,
- ]);
- }
-
- protected function findModel($id)
- {
- if (($model = CommentsSearch::findOne(['id' => $id])) !== null) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
|