代码之家  ›  专栏  ›  技术社区  ›  willbeeler

代码点火器分页-我被难住了

  •  5
  • willbeeler  · 技术社区  · 16 年前

    好的,我完全按照示例中的说明操作。最终,分页是可行的。

    第一个是主动的,就像它应该的那样。我也正确地进行了查询,因为每个链接都会产生正确的查询。

    但是,当我单击数字2时,它将正确地显示下一组产品,但它将显示第一页的分页。

    3 回复  |  直到 11 年前
        1
  •  10
  •   Stephen Curran    16 年前

    我想我可能知道发生了什么。您需要告诉分页库URL的哪个段包含偏移量。

    例如,如果您的URL是/products/browse/all/20,那么您需要告诉CodeIgniter第4段包含偏移量

    $config['uri_segment'] = 4;
    

    库的默认值是URL段#3。如果URL中的偏移量不在位置3,并且您忘记告诉分页库这一点,它会将错误的段解释为偏移量。这可能会导致您上面描述的那种分页似乎没有改变的行为。

        2
  •  1
  •   Sandeep Raul    14 年前

    =======>控制器

    // Default function
    function index()
    {   
        // Display listing      
        $this->listing();           
    }
    
    function listing($argDataArr = array()) 
    {   
    
        // Initialize pagination
        $pageArr['base_url']    = $this->config->item('categoryBeAction')."/listing";
        $pageArr['total_rows']  = 15; //assume
        $pageArr['per_page']    = 5; //assume
        //You need to tell the pagination library which segment of the URL holds the offset.        
        $pageArr['uri_segment']  = 4; //URL eg: http://localhost/myproject/index.php/backend/category/listing/5 
        $this->pagination->initialize($pageArr); 
    
        // Get list of categories
        // Create data array and pass data to get function
        $dataArr['limitRows']    = $pageArr['per_page'];
        $dataArr['limitOffset']  = $this->uri->segment(4); //the dynamic value from this segment will be used as offSet
        $viewArr['listArr'] = $this->category_model->get($dataArr);
    
        //rest of the code...
    
    }   
    

    function get($argDataArr = array())
    {   
    
        //Select the fields required
        $this->db->select('id, name, parent_id, status');
        $this->db->from($this->config->item('tbl_category','dbtables'));
    
        $this->db->where('parent_id', $parentId);   
        $this->db->limit($argDataArr['limitRows'], $argDataArr['limitOffset']); 
        $this->db->order_by("name", "asc");
            $query_result = $this->db->get(); 
    
        return  $query_result;
    }
    

                <!--  Pagination -->                    
                <tr> 
                <td align="right">
                    <?php  echo $this->pagination->create_links(); ?>                           
                </td> 
                </tr>
    
        3
  •  0
  •   stormdrain    16 年前

    哪一个例子?

    echo $this->pagination->create_links();
    

    推荐文章