Blame view

frontend/controllers/ArticlesController.php 1.33 KB
5842c37f   Administrator   big commti
1
2
3
4
5
6
7
8
9
10
11
12
13
  <?php
  
  namespace frontend\controllers;
  
  use Yii;
  use yii\web\Controller;
  use common\models\Articles;
  use yii\web\HttpException;
  use yii\data\Pagination;
  
  class ArticlesController extends Controller
  {
  
076b9c96   Administrator   big commti
14
      public function actionMain()
5842c37f   Administrator   big commti
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      {
              
                  $query = Articles::find()->groupBy('id')->orderBy('id DESC') ;
                  $countQuery = clone $query;
                  $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize'=>18]);
                  $pages->forcePageParam = false;
                  $pages->pageSizeParam = false;
                  $news = $query->offset($pages->offset)
                      ->with(['comments.rating', 'averageRating'])
                      ->limit($pages->limit)
                      ->all();
                  
              return $this->render('index', [
                  'pages'=>$pages,
                  'news'=>$news,
              ]);
      }
076b9c96   Administrator   big commti
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
      public function actionShow($translit){
          $news = $this->findModel($translit);
  
  
          return $this->render('show', [
              'news'=>$news,
          ]);
      }
      protected function findModel($translit)
      {
          if (($model = Articles::findOne(["translit"=>$translit])) !== null) {
              return $model;
          } else {
              throw new NotFoundHttpException('The requested page does not exist.');
          }
5842c37f   Administrator   big commti
47
48
49
      }
      
  }