public function action_index($user = null) { if ($user) { $data['posts'] = Model_Post::query()->related(array('author', 'category'))->where('author.username', $user)->get(); $this->template->title = "My Posts"; } else { $data['posts'] = Model_Post::find('all', array('related' => array('author', 'category'))); $this->template->title = "All Posts"; } $this->template->content = View::forge('admin/post/index', $data); }
public function action_index() { // Pagination configuration $config = array('per_page' => 3, 'uri_segment' => 'page'); // Get the category_slug route parameter $category_slug = $this->param('category_slug'); if (is_null($category_slug)) { $config['total_items'] = Model_Post::count(); } else { $config['total_items'] = Model_Post::count(array('where' => array('category_id' => Model_Category::find('first', array('where' => array(array('slug' => $category_slug))))->id))); } // Create a pagination instance named 'posts' $pagination = \Pagination::forge('posts', $config); $data['posts'] = Model_Post::query()->related(array('author', 'category'))->rows_offset($pagination->offset)->rows_limit($pagination->per_page); if (!is_null($category_slug)) { $data['posts']->where('category_id', Model_Category::find('first', array('where' => array(array('slug' => $category_slug))))->id); } $data['posts'] = $data['posts']->get(); $this->template->title = "Posts"; $this->template->content = View::forge('post/index', $data); $this->template->content->set('pagination', $pagination, false); }