我对产品有动态分页。我的分页工作正常,只是我想更好地查看我的分页。
视图:
<div style='margin-top: 10px;' class="page-link" align="center">
<?= $pagination; ?>
</div>
控制器:
function category($rowno=0)
{
$rootCatId = $this->input->get('rootCatId');
$subCatId = $this->input->get('subCatId');
$rowno = $this->input->get('per_page');
$data=array();
if($rootCatId > 0 && $subCatId== 0){
$rowperpage = 12;
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
$search_text = "";
if($this->input->post('submit') != NULL ){
$search_text = $this->input->post('search');
$this->session->set_userdata(array("search"=>$search_text));
}else{
if($this->session->userdata('search_product') != NULL){
$search_text = $this->session->userdata('search_product');
}
}
$rowperpage = 12;
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
$allcount = $this->product->getrecordCount($search_text);
$users_record = $this->product->fetchAllProductByMainCat($rootCatId,$rowno,$rowperpage,$search_text);
$config['base_url'] = base_url().'category';
$config['uri_segment'] = 3;
$config['reuse_query_string'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['page_query_string'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;
$config['cur_tag_open'] = ' <a class="page-link">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
// Initialize
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['viewAll'] = $users_record;
$data['row'] = $rowno;
$data['search'] = $search_text;
}elseif($rootCatId > 0 && $subCatId !==0 && $subCatId > 0){
$rowperpage = 12;
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
$search_text = "";
if($this->input->post('submit') != NULL ){
$search_text = $this->input->post('search');
$this->session->set_userdata(array("search"=>$search_text));
}else{
if($this->session->userdata('search_product') != NULL){
$search_text = $this->session->userdata('search_product');
}
}
$allcount = $this->product->getrecordCount($search_text);
$users_record = $this->product->fetchProductByCat($rootCatId,$subCatId,$rowno,$rowperpage,$search_text);
$config['base_url'] = base_url().'category';
$config['reuse_query_string'] = TRUE;
$config['enable_query_strings']=TRUE;
$config['page_query_string'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;
$config['cur_tag_open'] = ' <a class="page-link">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['viewAll'] = $users_record;
$data['row'] = $rowno;
$data['search'] = $search_text;
}
$data['get_website_content'] = $this->pg_model->get_website_content();
$data['BannerImage'] = $this->product->fetchBannerImage($rootCatId);
$data['MainName'] = $this->product->NameByMainCat($rootCatId);
$data['SubName'] = $this->product->NameBySubCat($subCatId);
$data['product_list_commercial'] = $this->pg_model->product_list_commercial();
$this->load->view('template/header',$data);
$this->load->view('category');
$this->load->view('template/footer');
}
我想让分页看起来像下图。
使用$config
设置分页的所有必要配置。我不知道我的代码哪里错了
答案 0 :(得分:2)
您做得不错,但未在自定义分页中添加html标签。只需在当前代码之间添加几行即可。
function category($rowno=0)
{
$rootCatId = $this->input->get('rootCatId');
$subCatId = $this->input->get('subCatId');
$rowno = $this->input->get('per_page');
$data=array();
if($rootCatId > 0 && $subCatId== 0){
$rowperpage = 12;
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
$search_text = "";
if($this->input->post('submit') != NULL ){
$search_text = $this->input->post('search');
$this->session->set_userdata(array("search"=>$search_text));
}else{
if($this->session->userdata('search_product') != NULL){
$search_text = $this->session->userdata('search_product');
}
}
$rowperpage = 12;
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
$allcount = $this->product->getrecordCount($search_text);
$users_record = $this->product->fetchAllProductByMainCat($rootCatId,$rowno,$rowperpage,$search_text);
$config['base_url'] = base_url().'category';
$config['uri_segment'] = 3;
$config['reuse_query_string'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['page_query_string'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;
$config['cur_tag_open'] = ' <a class="page-link">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
//This segment is used for the design (looks) start here
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['next_tag_open'] = '<li class="page-item">';
$config['next_tagl_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="page-item">';
$config['prev_tagl_close'] = '</li>';
$config['first_tag_open'] = '<li class="page-item disabled">';
$config['first_tagl_close'] = '</li>';
$config['last_tag_open'] = '<li class="page-item">';
$config['last_tagl_close'] = '</a></li>';
$config['attributes'] = array('class' => 'page-link');
$this->pagination->initialize($config);
//This segment is used for the design (looks) end here
// Initialize
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['viewAll'] = $users_record;
$data['row'] = $rowno;
$data['search'] = $search_text;
}elseif($rootCatId > 0 && $subCatId !==0 && $subCatId > 0){
$rowperpage = 12;
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}
$search_text = "";
if($this->input->post('submit') != NULL ){
$search_text = $this->input->post('search');
$this->session->set_userdata(array("search"=>$search_text));
}else{
if($this->session->userdata('search_product') != NULL){
$search_text = $this->session->userdata('search_product');
}
}
$allcount = $this->product->getrecordCount($search_text);
$users_record = $this->product->fetchProductByCat($rootCatId,$subCatId,$rowno,$rowperpage,$search_text);
$config['base_url'] = base_url().'category';
$config['reuse_query_string'] = TRUE;
$config['enable_query_strings']=TRUE;
$config['page_query_string'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;
$config['cur_tag_open'] = ' <a class="page-link">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
//This segment is used for the design (looks) start here
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li class="page-item">';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['next_tag_open'] = '<li class="page-item">';
$config['next_tagl_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="page-item">';
$config['prev_tagl_close'] = '</li>';
$config['first_tag_open'] = '<li class="page-item disabled">';
$config['first_tagl_close'] = '</li>';
$config['last_tag_open'] = '<li class="page-item">';
$config['last_tagl_close'] = '</a></li>';
$config['attributes'] = array('class' => 'page-link');
$this->pagination->initialize($config);
//This segment is used for the design (looks) end here
$data['pagination'] = $this->pagination->create_links();
$data['viewAll'] = $users_record;
$data['row'] = $rowno;
$data['search'] = $search_text;
}
$data['get_website_content'] = $this->pg_model->get_website_content();
$data['BannerImage'] = $this->product->fetchBannerImage($rootCatId);
$data['MainName'] = $this->product->NameByMainCat($rootCatId);
$data['SubName'] = $this->product->NameBySubCat($subCatId);
$data['product_list_commercial'] = $this->pg_model->product_list_commercial();
$this->load->view('template/header',$data);
$this->load->view('category');
$this->load->view('template/footer');
}
此后,您可以基于html上添加的class属性添加自定义CSS。
答案 1 :(得分:1)
如果您正在使用引导程序,则可以将以下代码与其他配置值一起使用
/* Pagination buttion style start */
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_link'] = '<i class="fa fa-chevron-left"></i>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '<i class="fa fa-chevron-right"></i>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
/* Pagination buttion style end */