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;
- /**
- * CommentsController implements the CRUD actions for Comments model.
- */
- class CommentsController extends BaseController
- {
- /**
- * @inheritDoc
- */
- public function behaviors()
- {
- return array_merge(
- parent::behaviors(),
- [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ]
- );
- }
- /**
- * Lists all Comments models.
- *
- * @return string
- */
- public function actionIndex()
- {
- $searchModel = new CommentsSearch();
- $dataProvider = $searchModel->search(\Yii::$app->request->get());
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- 'searchModel' => $searchModel,
- ]);
- }
- /**
- * Displays a single Comments model.
- * @param int $id
- * @return string
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- /**
- * Lists all Comments models.
- *
- * @return string
- */
- 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,
- ]);
- }
- /**
- * Finds the Comments model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param int $id
- * @return Comments the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = CommentsSearch::findOne(['id' => $id])) !== null) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
|