/** * List user comments with pagination * @return string * @throws \Ffcms\Core\Exception\NativeException * @throws \Ffcms\Core\Exception\SyntaxException */ public function actionIndex() { // set current page and offset $page = (int) $this->request->query->get('page'); $offset = $page * self::ITEM_PER_PAGE; // initialize active record model $query = new CommentPost(); // make pagination $pagination = new SimplePagination(['url' => ['comments/index'], 'page' => $page, 'step' => self::ITEM_PER_PAGE, 'total' => $query->count()]); // get result as active records object with offset $records = $query->orderBy('id', 'desc')->skip($offset)->take(self::ITEM_PER_PAGE)->get(); // render output view return $this->view->render('index', ['records' => $records, 'pagination' => $pagination]); }