2016-04-22 16 views
0

私のURLに問題があります。私のページネーションはとてもうまくいくが、それほど美しく見えない。 は、たとえば、私は2ページを参照したいとのリンクは次のようになります。ordonateページ番号codeigniter

if($this->uri->segment($config['uri_segment'])) 
    { 
     $offset = $this->uri->segment($config['uri_segment']); 
     $segment_to_replace = $this->uri->segment(2); 
     $new_id = $this->uri->segment(2)/9 +1; 
     $new_url = str_replace ($segment_to_replace, $new_id, current_url()); 
     redirect($new_url); 
    } 

しかし、コードが動作していない:localhost/page/9と3ページは、私はこの機能を試してみてくださいlocalhost/page/18 なります。 最初にvar_dup($new_url) localhost/page/2を返し、redirect($new_url)を返します。localhost/page/1.222222222を返します。 もう1つの問題は、連続的なリダイレクトです。どうすれば私のコードのオフセットではなく、curentページを表示するURLを作ることができます。

COMPLETE CODE:デフォルトでは

$this->load->library('pagination'); 

    $config['base_url'] = 'http://localhost/page/'; 

    $config['total_rows'] = $this->product_model->count('active'); 
    $config['per_page'] = 9; 
    $config['num_links'] = 3; 
    $config['uri_segment'] = 2; 
    $config['cur_tag_open'] = ' <b>'; 
    $config['prev_link'] = 'Previous'; 
    $config['next_link'] = 'Next'; 
    $this->pagination->initialize($config); 

    if($this->uri->segment($config['uri_segment'])) 
    { 
     $offset = $this->uri->segment($config['uri_segment']); 
     $segment_to_replace = $this->uri->segment(2); 
     $new_id = $this->uri->segment(2)/9 +1; 
     $new_url = str_replace ($segment_to_replace, $new_id, current_url()); 

     var_dump($new_url); die; 
     return redirect($new_url); 
    } 

答えて

1
$config['use_page_numbers'] = TRUE; 

、URIセグメントを使用すると、ページ付けされている 項目の開始インデックスを使用します。実際のページ番号を表示する場合は、 をTRUEに設定します。

Docs

+0

tnx man !!救いなさい! – RedoColor

+0

乾杯。ハッピーコーディング。 :) – Tpojka