Code Igniter Pagination和URL传递方法参数

时间:2013-08-13 17:54:48

标签: php codeigniter pagination codeigniter-routing

我的问题是,当我按分页链接更改URL CHANGE和段数组时,首先我开始使用此URL:

site/argument/argument

当我按下分页链接时,URL会变为:

site/method/startIndex.

有没有办法在不使用URL查询索引的情况下使用分页?

修改

这是我的控制器方法,我从URL接收参数:

function index ($par1, $par2 = null, $par3 = null)
{       
    $data['records'] = $this->site_model->getRecords($par1, $par2, $par3);

    $this->load->view('main', $data);
}

这是我进行数据库查询的Model方法:

function getRecords($par1, $par2 = null, $par3 = null )
{
    if (!isset($par2) && !isset($par3)) {
        $where = "lvlOne = '".$par1."'";

    } elseif(isset($par2) && !isset($par3)) {
        $where = "lvlOne = '".$par1."' AND lvlTwo = '".$par2."'";

    } elseif(isset($par2) && isset($par3)) {
        $where = "lvlOne = '".$par1."' AND lvlTwo = '".$par2."' AND lvlThree = '".$par3."'";
    }

    $this->db->from('mph_products');
    $this->db->where($where);
    $query = $this->db->get();


    return $query->result();
}

如何对此结果进行分页?因为我与分页库URL有冲突

修改

我找到了一种方法来做我想做的事。 Pagination Library有一个配置选项,你可以在其中放置分页锚的后缀,你可以将参数传递给它。

$ config ['suffix'] =“$ arg1 / $ arg2 / $ arg3”;

:d

2 个答案:

答案 0 :(得分:0)

据我了解,您不希望在网址中看到网页编号,但CI分页类始终会添加链接编号。有关详细信息,请参阅Pagination class

此外,您可以使用jquery datatable进行客户端或服务器分页。

答案 1 :(得分:0)

此库codeigniter分页+引导程序设计

<?php

class Paginacao
{
public $CI;

function __construct() {
    $this->CI = &get_instance();
    $this->CI->load->library('pagination');

}

function criar($total_rows,$base_url,$per_page=15,$num_links=5)
{
    $paginacao['total_rows'] = $total_rows;

        $paginacao['base_url'] = site_url($base_url);
        $paginacao['per_page'] = $per_page;
        $paginacao['num_links'] = $num_links;

        $paginacao['full_tag_open'] = '<br /><div class="pagination pagination-centered"><ul>';
        $paginacao['full_tag_close'] = '</ul></div>';

        $paginacao['first_link'] = 'Primeira';
        $paginacao['first_tag_open'] = '<li>';
        $paginacao['first_tag_close'] = '<li>';

        $paginacao['last_link'] = 'Ultima';
        $paginacao['last_tag_open'] = '<li>';
        $paginacao['last_tag_close'] = '</li>';

        $paginacao['next_link'] = 'Próximo';
        $paginacao['next_tag_open'] = '<li>';
        $paginacao['next_tag_close'] = '</li>';

        $paginacao['prev_link'] = 'Anterior';
        $paginacao['prev_tag_open'] = '<li>';
        $paginacao['prev_tag_close'] = '</li>';        

        $paginacao['cur_tag_open'] = '<li class="active"><a href="#">';
        $paginacao['cur_tag_close'] = '</a></li>';

        $paginacao['num_tag_open'] = '<li>';
        $paginacao['num_tag_close'] = '</li>';

        $this->CI->pagination->initialize($paginacao);
        $html = $this->CI->pagination->create_links();

    return $html;
}

}