frontend/controllers/PostController.php
/**
     * Lists all Post models.
     * @return mixed
     */
Lists all Post models.
@return mixed
Lists all Post models . @return mixed
public function actionIndex()
    {
        $query = Post::find()->orderBy(['created_at' => SORT_DESC])->with(['author', 'comments']);
        $countQuery = clone $query;
        $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]);
        $pages->pageSizeParam = false;
        $posts = $query->offset($pages->offset)
            ->limit($pages->limit)
            ->all();
        return $this->render('index', [
            'posts' => $posts,
            'pages' => $pages
        ]);
    }
public function actionIndex ( ) { $ query = Post :: find ( ) -> orderBy ( [ 'created_at' => SORT_DESC ] ) -> with ( [ 'author' , 'comments' ] ) ; $ countQuery = clone $ query ; $ pages = new Pagination ( [ 'totalCount' => $ countQuery -> count ( ) , 'pageSize' => 10 ] ) ; $ pages -> pageSizeParam = false ; $ posts = $ query -> offset ( $ pages -> offset ) -> limit ( $ pages -> limit ) -> all ( ) ; return $ this -> render ( 'index' , [ 'posts' => $ posts , 'pages' => $ pages ] ) ; }
Lists all Post models.
Lists all Post models .