controllers/AdminController.php
public function actionIndex($parent = null, $page = 1)
    {
        $searchModel = $this->module->model('ContentSearch');

        // list filter parameters correction
        $params = Yii::$app->request->queryParams;
        if ($parent === '-') { // to show all nodes
            $params['parent'] = $parent;
            unset($params[$searchModel->formName()]['parent_id']);
        } else {
            $params[$searchModel->formName()]['parent_id'] = $params['parent'] = intval($parent);
        }

        if (!Yii::$app->user->can('roleContentModerator') && Yii::$app->user->can('roleContentAuthor')) {
            $params[$searchModel->formName()]['owner_id'] = Yii::$app->user->id;
        }

        $dataProvider = $searchModel->search($params);

        $pager = $dataProvider->getPagination();
        $pager->pageSize = $this->pageSizeAdmin;
        $pager->totalCount = $dataProvider->getTotalCount();

        // page number correction:
        $maxPage = ceil($pager->totalCount / $pager->pageSize);
        if ($page > $maxPage) {
            $pager->page = $maxPage - 1;
        } else {
            $pager->page = $page - 1; //! from 0
        }

        return $this->render('index', compact('dataProvider', 'searchModel', 'params'));
    }
public function actionIndex($parent = null, $page = 1)
    {
        $searchModel = $this->module->model('ContentSearch');

        // list filter parameters correction
        $params = Yii::$app->request->queryParams;
        if ($parent === '-') { // to show all nodes
            $params['parent'] = $parent;
            unset($params[$searchModel->formName()]['parent_id']);
        } else {
            $params[$searchModel->formName()]['parent_id'] = $params['parent'] = intval($parent);
        }

        if (!Yii::$app->user->can('roleContentModerator') && Yii::$app->user->can('roleContentAuthor')) {
            $params[$searchModel->formName()]['owner_id'] = Yii::$app->user->id;
        }

        $dataProvider = $searchModel->search($params);

        $pager = $dataProvider->getPagination();
        $pager->pageSize = $this->pageSizeAdmin;
        $pager->totalCount = $dataProvider->getTotalCount();

        // page number correction:
        $maxPage = ceil($pager->totalCount / $pager->pageSize);
        if ($page > $maxPage) {
            $pager->page = $maxPage - 1;
        } else {
            $pager->page = $page - 1; //! from 0
        }

        return $this->render('index', compact('dataProvider', 'searchModel', 'params'));
    }
public function actionIndex ( $ parent = null , $ page = 1 ) { $ searchModel = $ this -> module -> model ( 'ContentSearch' ) ; // list filter parameters correction $ params = Yii :: $ app -> request -> queryParams ; if ( $ parent === '-' ) { // to show all nodes $ params [ 'parent' ] = $ parent ; unset ( $ params [ $ searchModel -> formName ( ) ] [ 'parent_id' ] ) ; } else { $ params [ $ searchModel -> formName ( ) ] [ 'parent_id' ] = $ params [ 'parent' ] = intval ( $ parent ) ; } if ( ! Yii :: $ app -> user -> can ( 'roleContentModerator' ) && Yii :: $ app -> user -> can ( 'roleContentAuthor' ) ) { $ params [ $ searchModel -> formName ( ) ] [ 'owner_id' ] = Yii :: $ app -> user -> id ; } $ dataProvider = $ searchModel -> search ( $ params ) ; $ pager = $ dataProvider -> getPagination ( ) ; $ pager -> pageSize = $ this -> pageSizeAdmin ; $ pager -> totalCount = $ dataProvider -> getTotalCount ( ) ; // page number correction: $ maxPage = ceil ( $ pager -> totalCount / $ pager -> pageSize ) ; if ( $ page > $ maxPage ) { $ pager -> page = $ maxPage - 1 ; } else { $ pager -> page = $ page - 1 ; //! from 0 } return $ this -> render ( 'index' , compact ( 'dataProvider' , 'searchModel' , 'params' ) ) ; }
Lists all Content models.
@param mixed $parent parent node id, '0' means show root children, '-' means show all nodes.
@param integer $page
@return mixed
Lists all Content models .