12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\controllers;
- use app\models\ReportTopic;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\data\ActiveDataProvider;
- class ReportTopicController extends \yii\web\Controller
- {
- public function actionIndex()
- {
- $news_query = ReportTopic::find()->where(['<>', 'title', ''])->where([ 'active'=>1]);
- $pages = new \yii\data\Pagination(['totalCount' => $news_query->count(), 'pageSize'=>50]);
- $gets = \Yii::$app->request->get();
- $valid_get = array_filter($gets, function($k) {
- $valid = ['page'=>true, 'per-page'=>false];
- return isset( $valid[$k] );
- }, ARRAY_FILTER_USE_KEY);
- $pages->pageSizeParam = false;
- // $pages->params = $valid_get;
- $pages->route = \Yii::$app->urlManager->createUrl(['photo']);
- $dataProvider = new ActiveDataProvider([
- 'query' => $news_query,
- 'pagination' => $pages,
- 'sort' => [
- 'defaultOrder' => [
- 'id' => SORT_DESC,
- ]
- ],
- ]);
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- ]);
- }
- public function actionView($topic){
- if( is_numeric($topic) ){
- $model = ReportTopic::findOne(['id'=>$topic]);
- if( ( !$model instanceof ReportTopic ) || $model->active == 0 ){
- throw new NotFoundHttpException("Стр. не найдена");
- }
- return $this->render("view",["model"=>$model]);
- }
- throw new NotFoundHttpException("Стр. не найдена");
- }
- public function actionWidget($topic){
- if( is_numeric($topic) ){
- $model = ReportTopic::findOne(['id'=>$topic]);
- if( ( !$model instanceof ReportTopic ) ){
- throw new NotFoundHttpException("Стр. не найдена");
- }
- return $this->renderPartial("widget",["model"=>$model]);
- }
- throw new NotFoundHttpException("Стр. не найдена");
- }
- }
|