2017-02-28 33 views
0

我在CI3中建立并从MSSQL数据库中提取数据(无偏移量,你在开玩笑吗?),所以我一直强迫从数组中分页(参见How to get CI pagination to work with a array();)。一切正常,我可以手动添加数字到网址(细分),并获得所需的结果,但我无法得到分页链接显示在所有。 我已经通过本网站上的其他类似问题,但似乎没有关系。 任何帮助将不胜感激。Codeigniter 3 - 从数组分页 - 链接没有显示

路线 - $route['orders/:num'] = 'orders/index';

模式只是拉行

控制器

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,作为一个块= 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

我想你还没有在你的视图文件,请您及时检查添加分页查看并添加下列行: -

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

我应该能够在发送到视图文件之前看到存储在变量$ data ['links']中的链接,但此时它是一个空字符串。 – Dale