Codeigniter 分页 - 我被难住了

发布于 2024-08-26 18:57:56 字数 254 浏览 9 评论 0原文

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

我得到列出的所有页面: 1 | 2 | > |最后的。等等。

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

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

无论我点击哪个分页按钮,都会返回主分页集:1(选定)| 2 | > |最后的。它永远不会改变!我失去了耐心,有人可以帮忙吗?

Ok, I followed the instructions in the example perfectly. Ultimately, pagination works, kind of.

I get all of the pages listed: 1 | 2 | > | Last. Etc.

The first one is active, like it should be. I did the querying correctly as well, because each link will result in the correct query.

However, when I click on number 2, it will show me the next set of products correctly, but it will display the pagination from the first page.

Whatever pagination button I click on, will return the main pagination set: 1 (selected) | 2 | > | Last. It never changes! I'm loosing my patience, can someone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

友谊不毕业 2024-09-02 18:57:56

我想我可能知道发生了什么事。您需要告诉分页库 URL 的哪一段保存偏移量。

例如,如果您的 URL 是 /products/browse/all/20,则需要告诉 CodeIgniter 第 4 段保存偏移量。

$config['uri_segment'] = 4;

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

I think I might know whats going on. You need to tell the pagination library which segment of the URL holds the offset.

For example, if your URL is /products/browse/all/20, you need to tell CodeIgniter that the 4th segment holds the offset

$config['uri_segment'] = 4;

The default for the library is URL segment #3. If the offset in your URL is not in position 3 and you forget to tell the pagination library this, it will interpret the wrong segment as being the offset. This can lead to the kind of behaviour you describe above where the pagination does not appear to change.

余罪 2024-09-02 18:57:56

我也遇到了同样的错误,最后能够修复它。只是想分享代码脚本,也许有人能够使用它。

=====>控制器

// 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>

I also came across same error and finally was able to fix it. Just thought to share the code script, may be someone will be able to use it.

=====> Controller

// 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...

}   

======> Model

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;
}

======> View page

            <!--  Pagination -->                    
            <tr> 
            <td align="right">
                <?php  echo $this->pagination->create_links(); ?>                           
            </td> 
            </tr>
小糖芽 2024-09-02 18:57:56

哪个例子?

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

^^您认为这是吗?

Which example?

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

^^Is this in your view?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文