2017-12-14 7 views
0

私はGETレコード検索方法を使用しています。今、私がページングを適用したとき、次のページページリンクにデータを提出する方法を理解できません。 私はこれを試しましたanswer。リンクセグメントにページ番号を積み重ねるだけです。ページネーション送信値を取得するcodeigniter

例:? はlocalhost/PHC /検索/結果/ 0から

S =が& product_catを愛=すべて& post_type =製品

はlocalhost/PHC /検索/結果/ ?s = ai & product_cat = all & post_type = product/12/24

私はそのコードを使用しませんでした。

そして今、私のコードは次のとおりです。

public function results() { 
     //pagination 
     $offset = $this->uri->segment(3); 
     $limit = 12; 
     //$offset = 0; 
     $data['limit'] = $limit; 
     $config['base_url'] = base_url() . 'search/results/'; 
     $config['first_url'] = base_url() .'search/results/0'; 

     $data['total'] = $this->All_data_model->countSearchProducts($_GET); 

     $config['total_rows'] = $data['total']; 
     $config['per_page'] = $limit; 
     $config['uri_segment'] = 3; 
     $config['next_link'] = 'Next'; 
     $config['prev_link'] = 'Previous'; 

     $this->pagination->initialize($config); 
     $data['pagination'] = $this->pagination->create_links(); 
     $data['offset'] = $offset; 
     $data['total_rows'] = $config['total_rows']; 


     $data['page'] = 'search'; 
     $data['navbar'] = $this->All_data_model->navbarContent(); 

     $data['products'] = $this->All_data_model->searchResults($_GET , $offset , $limit); 
     $this->template->write_view('content', 'products/search', $data); 
     $this->template->render(); 
    } 

は私がこのデータにアクセスできるか、この場合にデータを提出するための最良の方法はないにGET、どのように伝えます。

+0

'$ config ['reuse_query_string'] = TRUE;'はあなたが探しているものです。 –

答えて

1

入れは、あなたのURL

localhost/phc/search/results?s=ai&product_cat=all&post_type=product&offset=123 

にオフセットし、これらのconfigsを設定します。

$config['page_query_string'] = TRUE; 
$config['query_string_segment'] = 'offset'; 
$config['reuse_query_string'] = TRUE; 

コードが変更されましたが、全くテストされていません。

public function results() { 

    //pagination 

    $offset = $this->input->get('offset') ? $this->input->get('offset') : 0; 

    $limit = 12; 
    $data['limit'] = $limit; 

    $config['base_url'] = base_url() . 'search/results/'; 

    $data['total'] = $this->All_data_model->countSearchProducts($_GET); 

    $config['total_rows'] = $data['total']; 
    $config['per_page'] = $limit; 

    // set these mostly... 
    $config['page_query_string'] = TRUE; 
    $config['query_string_segment'] = 'offset'; 
    $config['reuse_query_string'] = TRUE; 

    $config['next_link'] = 'Next'; 
    $config['prev_link'] = 'Previous'; 

    $this->pagination->initialize($config); 
    $data['pagination'] = $this->pagination->create_links(); 
    $data['offset'] = $offset; 
    $data['total_rows'] = $config['total_rows']; 


    $data['page'] = 'search'; 
    $data['navbar'] = $this->All_data_model->navbarContent(); 

    $data['products'] = $this->All_data_model->searchResults($_GET , $offset , $limit); 

    $this->template->write_view('content', 'products/search', $data); 
    $this->template->render(); 
    } 
関連する問題