Codeigniter分页ID在url的最后一段

时间:2016-03-15 07:09:26

标签: php codeigniter pagination

您好我在其他网站有分页功能,但这里

Window -> Reset perspective

我无法理解为什么分页不起作用。如果URL在最后一段包含数字(id),我怎么能使分页工作?

2 个答案:

答案 0 :(得分:0)

将您的$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;更改为:

if($this->uri->segment(4))
            {
                $config["per_page"] = (($this->uri->segment(4)) * 6) - 6;
            }
            else
            {
                $config["per_page"] = 0;
            }

如下面的示例:

public function category($id=null)
            {
            $config = array();
            $config["base_url"] = base_url() . "view/category/".$id;
            $config["total_rows"] = $this->viewmodel->record_count_category_post($data['category']);
            $config["per_page"] = 6;
            $config['num_links'] = 10;
            $this->pagination->initialize($config);  
        if($this->uri->segment(4))
                {
                    $config["per_page"] = (($this->uri->segment(4)) * 6) - 6;
                }
                else
                {
                    $config["per_page"] = 0;
                }
        $config['display_pages'] = FALSE;
         $data["links"] = $this->pagination->create_links();

         }

答案 1 :(得分:0)

变化 public function category($id=null)

public function category($id=0)

因为NULL不会返回任何细分......