2017-02-28 7 views
0

私はCI3に構築し、(?いいえ、あなたは冗談されているオフセット)MSSQLデータベースからデータを引っ張って、私は配列からページ付けする力となってきています(参照リンクが表示されませんHow to get CI pagination to work with a array();)。すべてが動作している、私は手動でURL(セグメント)に数字を追加し、必要な結果を得ることができますが、私はまったく表示するページネーションリンクを得ることができません。 私はこのサイトで他の同様の質問をしてきましたが、関係するものはありません。 ご協力いただければ幸いです。CodeIgniterの3 - 配列からページネーション -

ルート - 行だけ

コントローラ

public function index() 
    { 
     // Load Pagination Library 
     $this->load->library('pagination'); 
     // Get results from MSSQL database 
     $pages = $this->orders_m->get_orders($this->session->customer_code); 
     // Initiate chunks array to create pages 
     $chunks = array(); 
     // Offset used to index of chunk arrays to display relevent results, default to 1 if segment is missing. 
     $offset = $this->uri->segment(2,1); 
     // How many items to show per page 
     $limit = 10; 
     // an index you can use to find offsets for pagination 
     $index=0; 
     // count the retured results from the query 
     $count = count($pages); 

    // loop through the pages array in chunks, and create 
    // an index or offset you can query from 
    foreach(array_chunk($pages, $limit) as $page){ 
     $index++; 
     $chunks[$index] = $page; // build your array 
    } 
    // add to a data array to be passed to the view 
    $data['orders'] = $chunks[$offset]; 
    // Set config options for the pagination class 
    $config = array(
     $config['base_url'] = base_url().'orders/', 
     $config['uri_segment'] = 2, 
     $config['total_rows'] = $count, 
     $config['per_page'] = $limit, 
     $config['display_pages'] = TRUE 
    ); 
    // Initialise the pagination class 
    $this->pagination->initialize($config); 
    // Add the links to a data variable to be sent to the view 
    $data['links'] = $this->pagination->create_links(); // FAIL 

    // The 'why the fuck isn't it working' test procedure 

    print_r($data['links'])."<br>"; //FAIL; 

    print_r($config)."<br>"; //OK 

    echo $count."<br>"; //OK 

    echo $offset."<br>"; //OK 

    echo "<pre>"; 
    print_r($data['orders']); //OK 
    echo "</pre>";  
     //$this->load->view('elements/header'); 
     //$this->load->view('orders', $data); 
     //$this->load->view('elements/footer');  
    } 

答えて

0

解決済みです。データベースから行を引き出すのではなく、配列のチャンクを1ページに1つのチャンク= 10行として使用しています。

$config['base_url'] = base_url('orders'); 
     $config['total_rows'] = ceil($count/$limit); 
     $config['per_page'] = 1; 
     $config['use_page_numbers'] = TRUE; 
     $config['num_links'] = 5; 

この方法をとにかく終了し、データテーブルを使用してデータを操作し、改ページを実行しました。

0

私はあなたのビューファイルしなさいチェックで改ページビューを追加していないと思う引っ張る$route['orders/:num'] = 'orders/index';

モデル次の行を追加します。 -

<div class="pagination" style="float:right; margin:20px 0px 20px 0px;"> 
     <ul> 
      <?php echo $pagination_links; ?> 
     </ul> 
    </div> 
+0

変数$ data ['links']に保存されているリンクをビューファイルに送信する前に見ることができるはずです。現時点では空文字列です。 – Dale

関連する問題