简体   繁体   English

网址最后一段的Codeigniter分页ID

[英]Codeigniter pagination id at the last segment of url

Hi I have working pagination function in other sites but here 嗨,我在其他网站上有工作分页功能,但是在这里

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

}

I could not figure why pagination not working. 我不知道为什么分页不起作用。 How could I make pagination working if the URL contains number (id) at the last segment ? 如果网址的最后一段包含数字(id),我如何使分页工作?

Change your $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; 更改您的$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; to: 至:

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

Like this Sample Below: 像下面的示例:

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

         }

change public function category($id=null) to public function category($id=null)更改为

public function category($id=0)

Because NULL will not return any segment... 因为NULL不会返回任何段...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM