Blame view

app/controllers/NewsController.php 1.17 KB
bf807468   Alex Savenko   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  <?php

  

  namespace app\controllers;

  

  use Yii;

  use yii\web\Controller;

  use app\models\News;

  use yii\web\HttpException;

  use yii\data\Pagination;

  

  class NewsController extends Controller

  {

  

      public function actionIndex()

      {

              

                  $query = News::find()->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)

                      ->limit($pages->limit)

                      ->all();

                  

              return $this->render('index', [

                  'pages'=>$pages,

                  'news'=>$news,

              ]);

      }

      

      public function actionShow(){

          if(!$news = News::find()->where(['id'=>$_GET['id']])->one())

                      throw new HttpException(404, 'Данной странице не существует!');        

      

              return $this->render('show', [

                  'news'=>$news,

              ]);

      }

      

  }