我现在所拥有的就像100 divs样式设置为连续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 id
和where date > NOW()
,这怎么办?我可以用什么替换此get和代码,使其仍然可以工作,并且视图又是WITHOUT表,是divs
中的foreach
。谢谢!
最佳答案
尝试这个:
控制器功能
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();
}