分页在codeigniter中不起作用

时间:2017-07-27 11:37:41

标签: codeigniter

我做了一个可选的搜索,让用户搜索用户名或客户或日期从/到结果返回到第一页但是如果我点击另一页,结果将不返回

这是我的前面和所有输入可选 我认为问题是分页路径,因为如果我填写所有输入分页路径变为

controllername/userid/customerid/fromdate/todate

如果跳过任何输入,我发现缺少分页路径

enter image description here

这是我的控制器

public function search($page_num = 1){
    $this->load->library('pagination');
    $this->load->helper("url");
    $this->load->model(array('CustomReport_m','user','Customer_m')); // This array to save number of lines only
    $username=$this->input->post('select_user');
    $username = ($this->uri->segment(3)) ? $this->uri->segment(3) : $username;
    $customer=$this->input->post('select_customer');
    $customer = ($this->uri->segment(4)) ? $this->uri->segment(4) : $customer;
    $datefrom=$this->input->post('from');
    $datefrom = ($this->uri->segment(5)) ? $this->uri->segment(5) : $datefrom;
    $dateend=$this->input->post('to');
    $dateend = ($this->uri->segment(6)) ? $this->uri->segment(6) : $dateend;
    $total_row = $this->CustomReport_m->search_count($username,$customer,$datefrom,$dateend);
    //$config['use_page_numbers'] = TRUE;
    $config['base_url'] = site_url("CustomReport/search/$username/$customer/$datefrom/$dateend");
    $config['total_rows'] = $total_row;
    $config['per_page'] = 10;
    $choice = $config["total_rows"]/$config["per_page"];
    $config["num_links"] = floor($choice);
    $config['full_tag_open'] = '<ul class="pagination">';
    $config['full_tag_close'] = '</ul>';
    $config['first_link'] = false;
    $config['last_link'] = false;
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['prev_link'] = '&laquo';
    $config['prev_tag_open'] = '<li class="prev">';
    $config['prev_tag_close'] = '</li>';
    $config['next_link'] = '&raquo';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $this->pagination->initialize($config);
    if ($this->uri->segment(7)) {
        $page = ($this->uri->segment(7));
    } else {
        $page = 1;
    }
    $str_links = $this->pagination->create_links();
    $data["links"]= explode('&nbsp;', $str_links);
    $data['users']=$this->user->display_users();
    $data['userdata'] = $this->user->userdata();
    $data['customers']= $this->Customer_m->index();
    // if(isset($_POST['submit'])){
     $data["rsl"] =$this->CustomReport_m->search($username,$customer,$datefrom,$dateend,$config["per_page"],$page);
        $this->load->view('customreport_v',$data);
   // }else{
   //    redirect('CustomReport','refresh');
   // }
}

这是我的模特

public function search_count($username,$customer,$datefrom,$dateend) {
    $this->db->select('*');
    $this->db->from('transactions');
    if (!empty($customer)){
    $this->db->where('t_customer_id',$customer);
    }
    if (!empty($username)){
    $this->db->where('t_u_id',$username);
    }
    if (!empty($dateend)){
    $this->db->where('t_date <=',$dateend);
    }
    if (!empty($datefrom)){
    $this->db->where('t_date >=',$datefrom);
    }
    return $this->db->get()->num_rows();
}
public function search($username,$customer,$datefrom,$dateend,$limit,$start)
{

    $start=$start-1;
    $this->db->select('*');
    $this->db->from('transactions');
    if (!empty($customer)){
    $this->db->where('t_customer_id',$customer);
    }
    if (!empty($username)){
    $this->db->where('t_u_id',$username);
    }
    if (!empty($dateend)){
    $this->db->where('t_date <=',$dateend);
    }
    if (!empty($datefrom)){
    $this->db->where('t_date >=',$datefrom);
    }

    $this->db->limit($limit,$start);
    $query=$this->db->get();
    if($query->num_rows() > 0){
        return $query->result();
    }else{
        return $query->result();
    }
}

这是我的路线

$route['CustomReport/(:num)']="CustomReport/index/$1";

0 个答案:

没有答案