【问题标题】:Codeigniter pagination id at the last segment of urlurl最后一段的Codeigniter分页ID
【发布时间】:2016-06-30 12:05:06
【问题描述】:

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

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),我如何使分页工作?

【问题讨论】:

标签: php codeigniter pagination


【解决方案1】:

将您的 $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();

         }

【讨论】:

    【解决方案2】:

    改变 public function category($id=null)

    public function category($id=0)

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

    【讨论】:

      猜你喜欢
      • 2017-08-25
      • 1970-01-01
      • 2017-03-04
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 2012-02-20
      • 1970-01-01
      相关资源
      最近更新 更多