public function index($req, $res, $args) { // Get number of pages $nbThemes = ORM::for_table('market_themes')->where('status', 2)->count(); $nbPages = ceil(($nbThemes + 1) / 20); // Determine the offset $p = !isset($args['page']) || $args['page'] <= 1 || $args['page'] > $nbPages ? 1 : intval($args['page']); $offset = 20 * ($p - 1); // Generate paging links $pagination = Router::paginate($nbPages, $p, 'themes/#'); $themes = ThemeModel::getIndex($offset); return View::setPageInfo(['themes' => $themes, 'pagination' => $pagination, 'title' => 'Themes', 'active_nav' => 'themes', 'top_right_link' => ['url' => Router::pathFor('themes.create'), 'text' => 'Add theme']])->addBreadcrumb(['Themes'])->addTemplate('themes/index.php')->display(); }