0

我现在拥有的就像 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);

    }

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

但是我需要在其中添加更多过滤器,例如order by id并且where date > NOW(),这怎么可能呢?我可以替换这个 get 并且代码仍然可以工作,并且视图再次没有表,divs位于foreach.

谢谢!

4

1 回答 1

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();
}
于 2013-09-10T11:07:37.080 回答