controllers/AdminController.php
public function actionIndex($page = 1, $id = 0)
    {
        $searchModel = new NewsSearch();
        $params = Yii::$app->request->queryParams;
        if (!Yii::$app->user->can('roleNewsModerator') && Yii::$app->user->can('roleNewsAuthor')) {
            $params[$searchModel->formName()]['owner_id'] = Yii::$app->user->id;
        }//var_dump($params);
        $dataProvider = $searchModel->search($params);

        $pager = $dataProvider->getPagination();
        $pager->pageSize = $this->module->params['pageSizeAdmin'];
        $pager->totalCount = $dataProvider->getTotalCount();

        // page number correction:
        //if ($pager->totalCount <= $pager->pageSize || $page > ceil($pager->totalCount / $pager->pageSize) ) {
        //    $pager->page = 0; //goto 1st page if shortage records
        $maxPage = ceil($pager->totalCount / $pager->pageSize);
        if ($page > $maxPage) {
            $pager->page = $maxPage - 1;
        } else {
            $pager->page = $page - 1; //! from 0
        }//var_dump($page);var_dump($pager->page);

        return $this->render('index', [
            'searchModel'  => $searchModel,
            'dataProvider' => $dataProvider,
            'currentId'    => $id,
        ]);
    }
public function actionIndex($page = 1, $id = 0)
    {
        $searchModel = new NewsSearch();
        $params = Yii::$app->request->queryParams;
        if (!Yii::$app->user->can('roleNewsModerator') && Yii::$app->user->can('roleNewsAuthor')) {
            $params[$searchModel->formName()]['owner_id'] = Yii::$app->user->id;
        }//var_dump($params);
        $dataProvider = $searchModel->search($params);

        $pager = $dataProvider->getPagination();
        $pager->pageSize = $this->module->params['pageSizeAdmin'];
        $pager->totalCount = $dataProvider->getTotalCount();

        // page number correction:
        //if ($pager->totalCount <= $pager->pageSize || $page > ceil($pager->totalCount / $pager->pageSize) ) {
        //    $pager->page = 0; //goto 1st page if shortage records
        $maxPage = ceil($pager->totalCount / $pager->pageSize);
        if ($page > $maxPage) {
            $pager->page = $maxPage - 1;
        } else {
            $pager->page = $page - 1; //! from 0
        }//var_dump($page);var_dump($pager->page);

        return $this->render('index', [
            'searchModel'  => $searchModel,
            'dataProvider' => $dataProvider,
            'currentId'    => $id,
        ]);
    }
public function actionIndex ( $ page = 1 , $ id = 0 ) { $ searchModel = new NewsSearch ( ) ; $ params = Yii :: $ app -> request -> queryParams ; if ( ! Yii :: $ app -> user -> can ( 'roleNewsModerator' ) && Yii :: $ app -> user -> can ( 'roleNewsAuthor' ) ) { $ params [ $ searchModel -> formName ( ) ] [ 'owner_id' ] = Yii :: $ app -> user -> id ; } //var_dump($params); $ dataProvider = $ searchModel -> search ( $ params ) ; $ pager = $ dataProvider -> getPagination ( ) ; $ pager -> pageSize = $ this -> module -> params [ 'pageSizeAdmin' ] ; $ pager -> totalCount = $ dataProvider -> getTotalCount ( ) ; // page number correction: //if ($pager->totalCount <= $pager->pageSize || $page > ceil($pager->totalCount / $pager->pageSize) ) { //    $pager->page = 0; //goto 1st page if shortage records $ maxPage = ceil ( $ pager -> totalCount / $ pager -> pageSize ) ; if ( $ page > $ maxPage ) { $ pager -> page = $ maxPage - 1 ; } else { $ pager -> page = $ page - 1 ; //! from 0 } //var_dump($page);var_dump($pager->page); return $ this -> render ( 'index' , [ 'searchModel' => $ searchModel , 'dataProvider' => $ dataProvider , 'currentId' => $ id , ] ) ; }
Lists all News models.
@return mixed
Lists all News models .