【发布时间】:2017-12-17 14:06:58
【问题描述】:
所以这是我以前的。如果我去 ciblog/categories/posts/5/,它会将我带到一个页面,该页面显示所有类别 ID 为 5 的帖子。
这就是我想要做的。我想去 ciblog/categories/posts/5,它会显示 5 个帖子让我们说。然后当我转到 ciblog/categories/posts/5/3 时,它会偏移 3,所以现在我有接下来的 3 个帖子。
目前我有 4 个帖子,仅用于测试。如果我直接通过我的 url 去 ciblog/categories/posts/5 它显示 3 个帖子,如果我去 ciblog/categories/posts/5/3 它显示我的另一个帖子,所以我得到的帖子数量是根据网址正确。
但在底部它总是显示我在第 2 页。当我使用 F12 并查看元素时,我的两个分页链接都显示 ciblog/categories/posts/5 所以它没有在最后添加数字
这是我为此页面的分页所拥有的内容。我使用了 print_r 并且 $config 中的所有内容都是正确的。
public function posts($id, $offset=0){
$category = $this->category_model->get_category($id);
if(empty($category))
{
show_404();
}
$config['base_url'] = base_url().'categories/posts/'.$id;
$config['total_rows'] = $this->post_model->get_posts_by_category_count($id);
$config['per_page'] = 3;
$config['uri_segment'] = 3;
$config['attributes'] = array('class' => 'pagination-link');
$this->pagination->initialize($config);
$data['title'] = $category->name;
$data['posts'] = $this->post_model->get_posts_by_category($id,$config['per_page'],$offset);
$this->load->view('templates/header');
$this->load->view('posts/index', $data);
$this->load->view('templates/footer');
}
路线:
$route['categories/posts/(:num)/(:num)'] = 'categories/posts/$1/$2';
参考:
我一直在关注这里的教程:https://www.youtube.com/watch?v=WoQTjJepDWM&index=8&list=PLillGF-RfqbaP_71rOyChhjeK1swokUIS 本教程的代码在这里:https://github.com/bradtraversy/ciblog
我现在对此进行补充。我所做的唯一更改如上所示
【问题讨论】:
-
你能在你的帖子视图中显示什么吗?
标签: php codeigniter codeigniter-3