Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter分页显示我在最后一页_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php Codeigniter分页显示我在最后一页

Php Codeigniter分页显示我在最后一页,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,这就是我以前的经历。如果我去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/cate

这就是我以前的经历。如果我去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,它会显示我的另一篇文章,因此根据url,我得到的文章数量是正确的

但在底部,它总是显示我在第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';
参考资料:

我一直在遵循以下教程: 本教程的代码如下:

我现在再补充一点。我所做的唯一更改如上所示

$config['base_url'] = base_url().'categories/posts/'. $id . '/' . $offset;
$config['uri_segment'] = 4;
因为分页取决于偏移量,而不是类别id,所以应该让它查找uri_段4的偏移量,并且基本url必须发送一个偏移量变量来查找偏移量


因为您的分页取决于偏移量,而不是类别id,那么您应该让它查找uri_段4的偏移量,并且您的base_url必须发送一个偏移量变量来查找偏移量。

您可以显示posts视图上的内容吗?您可以显示posts视图上的内容吗?当我使用$config['base_url']=base_url().'categories/posts/'时$id.“/”$抵消;最终的结果是,它会生成一个ciblog/categories/posts/5/0/3的url。我删除了它,只将uri部分保留为4,它就工作了。所以它现在起作用了是的,对你有好处。如果你像那样使用uri_段,你不需要路由,路由只会让你的url变短或者做其他事情。当我使用$config['base_url']=base_url()。'categories/posts/'时$id.“/”$抵消;最终的结果是,它会生成一个ciblog/categories/posts/5/0/3的url。我删除了它,只将uri部分保留为4,它就工作了。所以它现在起作用了是的,对你有好处。若你们使用这样的uri_段,你们不需要路由,路由只会让你们的url变短或者其他什么。