没有表格的CodeIgniter分页

时间:2013-09-10 10:57:22

标签: php mysql codeigniter pagination

我现在所拥有的就像100个div被设计为连续4个,想要添加分页,并且我成功使用了这段代码:

public function func() {
        $this->load->library('pagination');
        $this->load->database('default');
        $this->load->model('s_model');

        $data['all_rows_s'] = $this->s_model->count_all_s();
        $data['$total_s'] = $config['total_s'] = $this->s_model->count_all_ss();

        $config['base_url'] = 'http://example.com/display/s/';
        $config['total_rows'] = $data['all_rows_s'];
        $config['per_page'] = 12;
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<div class="page_row">';
        $config['full_tag_close'] = '</div>';

        $data['row'] = $this->db->get('s_data',$config['per_page'], $this->uri->segment(3))->result();

        $this->pagination->initialize($config);


        $this->template->set_theme(Settings_model::$db_config['active_theme']);
        $this->template->set_layout('main');
        $this->template->title($this->lang->line('s'));
        $this->process_partial('header', '/header');
        $this->process_partial('footer', '/footer');
        $this->process_template_build('s_view', $data);

    }

但是,这是有效的,因为WITHOUT表因为这行: $data['row'] = $this->db->get('s_data',$config['per_page'], $this->uri->segment(3))->result();

但是我需要在其中添加更多过滤器,例如order by idwhere date > NOW(),这怎么可能呢?取而代之的是这个get和代码仍然有用,并且视图是WITHOUT table,divs中的foreach

谢谢!

1 个答案:

答案 0 :(得分:0)

试试这个:
控制器功能

function func() {
    $this->load->library('pagination');
    $this->load->database('default');
    $this->load->model('s_model');

    $data['all_rows_s'] = $this->s_model->count_all_s();
    $data['$total_s'] = $config['total_s'] = $this->s_model->count_all_ss();

    /*Pagination*/
    $config['base_url'] = 'http://example.com/display/s/';
    $config['total_rows'] = $data['all_rows_s'];
    $config['per_page'] = 12;
    $config['num_links'] = 5;
    $config['full_tag_open'] = '<div class="page_row">';
    $config['full_tag_close'] = '</div>';
    /*Pagination*/

    //$data['row'] = $this->db->get('s_data',$config['per_page'], $this->uri->segment(3))->result();

    $data['row'] = $this->s_model->get_records($config['per_page'], $this->uri->segment(3));

    $this->pagination->initialize($config);


    $this->template->set_theme(Settings_model::$db_config['active_theme']);
    $this->template->set_layout('main');
    $this->template->title($this->lang->line('s'));
    $this->process_partial('header', '/header');
    $this->process_partial('footer', '/footer');
    $this->process_template_build('s_view', $data);

}

模型功能

function get_records($limit, $offset = 0){
    return $this->db->where('date > NOW()')->order_by('id', 'asc')->get('s_data', $limit, $offset)->result();
}