我创建了一个运行良好的分页页面。但是在我把它放入模板后,它会出错。我该如何配置?
这是我的模板库:
class Template {
var $template_data = array();
function set($name, $value)
{
$this->template_data[$name] = $value;
}
function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
return $this->CI->load->view($template, $this->template_data, $return);
}
}
默认视图模板:
<div id="header">
<?php $this->load->view('admin/layout/header');?>
</div>
<div id="sidebar">
<?php $this->load->view('admin/layout/sidebar');?>
</div>
<div id="content"><?= $contents ?></div>
<div id="footer">
<?php $this->load->view('admin/layout/footer');?>
</div>
分页方法:
function paging_kategori(){
if (isset($_POST['tblcari'])) {
$data['ringkasan'] = $this->input->post('cari');
// se session userdata untuk pencarian, untuk paging pencarian
$this->session->set_userdata('sess_ringkasan', $data['ringkasan']);
}
else {
$data['ringkasan'] = $this->session->userdata('sess_ringkasan');
}
$total = 4;
$this->load->model('mkategori');
$this->db->like('nama_kategori', $data['ringkasan']);
$this->db->from('kategori');
$config['per_page'] = $total;
$config['uri_segment'] = 3;
$config['num_links'] = 5;
$config['base_url'] = base_url().'ckategori/paging_kategori';
$config['total_rows'] = $this->db->count_all_results();
$config['full_tag_open'] = "<ul class='pagination pagination-sm' style='position:relative; top:-25px;'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$offset = $this->uri->segment(3,0);
$data['hasil'] = $this->mkategori->get_data_paging($config['per_page'],$offset,$data['ringkasan']);
$data['offset'] = $offset;
//$this->load->vars($data);
$this->template->load('admin/template','admin/vkategori',$data);
}
我认为错误发生在$config [' base_url ']
上。如果我想将分页页面显示到模板系统中,如何设置它?
答案 0 :(得分:0)
解决了-----我将url_segment更改为$config['uri_segment'] = 4;
和$offset = $this->uri->segment(4,0);