2016-06-28 88 views
0

我的控制器工作: -分頁鏈接不codeginiter

function all_leads($offset = 0) { 
    $where = ''; 
    $search['search_status'] = FALSE; 
    $username = $this->session->userdata('username'); 
    $user_id = $this->extra_functions->get_user_id($username); 
    $this->load->library('pagination'); 
    $user_type = $this->extra_functions->get_user_type($user_id); 
    if ($this->input->get('search')) { 
     $serach_string = $this->input->server('QUERY_STRING'); 
     $config['enable_query_strings'] = TRUE; 
     $config['suffix'] = '?' . $serach_string; 
     $search_data = $this->input->get(); 
     $where = $this->lead_model->lead_search_coundtiotn($search_data); 
     if ($where != NULL) { 
      $where = $where; 
     } else { 
      $where = ''; 
     } 
     $main_data['search'] = TRUE; 
     $main_data['search_data'] = $search_data; 
    } 
    $num_rows = $this->lead_model->count_leads($user_id, $user_type, $where); 
    $config['base_url'] = base_url('lead/all_leads'); 
    $config['total_rows'] = $num_rows; 
    $config['per_page'] = 10; 
    $config['use_page_numbers'] = TRUE; 
    $config['full_tag_open'] = '<ul class="pagination">'; 
    $config['full_tag_close'] = '</ul>'; 
    $config['prev_link'] = '&laquo;'; 
    $config['prev_tag_open'] = '<li>'; 
    $config['prev_tag_close'] = '</li>'; 
    $config['next_tag_open'] = '<li>'; 
    $config['next_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>'; 
    $config['num_links'] = 5; 
    $config['first_link'] = 'First'; 
    $config['first_tag_open'] = '<li>'; 
    $config['first_tag_close'] = '</li>'; 
    $config['last_link'] = 'Last'; 
    $config['last_tag_open'] = '<li>'; 
    $config['last_tag_close'] = '</li>'; 
    $config['next_link'] = '&raquo;'; 
    $this->pagination->initialize($config); 
    $main_data['all_leads'] = $this->lead_model->view_leads_sec($config['per_page'], $offset, $search, $user_id, $user_type, $where);  
    $main_data['totalRecords']=$num_rows; 
    $this->load->view('crm/leads/all_leads', $main_data);   
} 
+0

什麼是錯誤? – Hassaan

+0

它不顯示任何錯誤只是分頁鏈接不正常工作。它跳過一些記錄時,我試圖搜索任何東西。搜索工作正常只是分頁鏈接不工作正常... – Ruhanika

+0

你設置會話和偏移值應該根據你的url_segment – riya

回答

0
 $searchterm =$this->search_resource_model->searchterm_handler($this->input->post('keywords')); 

        //if serachterm is presnt 
          if($searchterm) 
          { 
          //pagenation code 
      $offset = ($this->uri->segment(3) != '' ? $this->uri->segment(3): 0); 
     $config['total_rows']=$this->search_resource_model->total_count($searchterm); 
          $config['per_page']= 5; 
          $config['first_url'] = '1'; 
          $config['prev_link'] = 'Prev'; 

          $config['first_link'] = 'First'; 
          $config['last_link'] = 'Last'; 
          $config['base_url']= base_url().'search/search_by_keywords/'; 
        $config['uri_segment'] = 3; 
    $data["reso_list"] = $this->search_resource_model->serch_with_kw($config["per_page"], $offset,$searchterm); 


         //total count to display on view page 
         $data["total_count"]=$config['total_rows']; 

         //initialize config variable 
         $this->pagination->initialize($config); 
         //create link for pagination 
         $data['paginglinks'] = $this->pagination->create_links(); 
          } 



//where in searchterm_handler i am setting session 
public function searchterm_handler($searchterm) 
{ 
    if($searchterm) 
    { 
     $this->session->set_userdata('searchterm', $searchterm); 
     return $searchterm; 
    } 
    elseif($this->session->userdata('searchterm')) 
    { 
     $searchterm = $this->session->userdata('searchterm'); 
     return $searchterm; 
    } 
    else 
    { 
     $searchterm =""; 

     return $searchterm; 
    } 
} 
+0

它,不工作@riya – Ruhanika

+0

請設置適當的偏移值。我想你使用$ this-> uri-> segment(3)它依賴於你的url。我使用這個,因爲它是我的url參數的完美。請告訴我你的網址我會讓你知道你的補償值是什麼 – riya

+0

我已經嘗試過段值4,5,但是還是不行。以下是我的網址: - http://192.168.1.109/emr/lead/all_leads/2?createdatefrom=2016-05-01&createdateto=2016-06-30&leadname=&service_s=&leadowner=&city_s=&mobile_num=&followup_date_from=&followup_date_to=&lead_src= &lead_status =&search = search – Ruhanika

-1

使用自動加載圖書館在config文件夾

EXP:

$autoload['libraries'] = array('database','session','encrypt','pagination'); 

這是我的分頁樣式,可能對你有用。

我的控制器:

public function album($id){ 
     $id = $this->uri->segment(3); 
     $encpt = $this->encrypt->encode('howmuch?'); 
     # fetch records from database 
     //$this->data['posts'] = $this->Punjabi_Model->fetch_top_album($id); 
     $config = array(); 
     $config["base_url"] = base_url() . "punjabi_music/album/".$id.'/'; 
     $config["total_rows"] = $this->Punjabi_Model->total_record($id); 
     $config["per_page"] = 20; 
     $config["uri_segment"] = 4; 

     $this->pagination->initialize($config); 

     $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; 
     $this->data['posts'] = $this->Punjabi_Model->fetch_top_album($id,$config["per_page"], $page); 
     $this->data['links'] = $this->pagination->create_links(); 


     $this->middle ='other/punjabi_music/album'; 
     $this->layout(); 

    } 
+0

@ChrisF這位用戶是垃圾郵件發送者,發送了'phpcomment'內容。你爲什麼編輯這個?看到這個:http://stackoverflow.com/a/38076469 –

+3

@PraveenKumar - 這至少是一個答案的嘗試。它包括代碼和使用說明。一旦鏈接被刪除沒有問題。 – ChrisF