代码点火器分页 ID 位于 url 的最后一段


Codeigniter pagination id at the last segment of url

嗨,我在其他站点有工作分页功能,但在这里

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);  
    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
    $config['display_pages'] = FALSE;
    $data["links"] = $this->pagination->create_links();
}

我不明白为什么分页不起作用。如果 URL 在最后一段包含数字 (id),我如何使分页工作?

$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();
         }

更改 public function category($id=null)

public function category($id=0)

因为NULL不会返回任何段...