Codeigniter 3-来自数组的分页-链接未显示 [英] Codeigniter 3 - pagination from array - links not showing up

查看:94
本文介绍了Codeigniter 3-来自数组的分页-链接未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建CI3并从MSSQL数据库中提取数据(没有偏移量,在开玩笑吗?),所以我被迫从数组中分页(请参阅如何获取CI分页以与array(); )一起使用。一切正常,我可以手动将数字添加到url(段)中并获得所需的结果,但我根本无法显示分页链接。
我曾经在此站点上经历过其他类似的问题,但似乎都没有关系。
任何帮助将不胜感激。

I'm building in CI3 and pulling data from a MSSQL database (no offset, are you kidding?), so i've been force to paginate from an array (see How to get CI pagination to work with a array();). Everything is working, I can manually add digits to the url (segment) and get the required results but i can't get the pagination links to show up at all. I have been through the other similar questions on this site but none seem to relate. Any Help would be greatly appreciated.

路线- $ route ['orders /:num '] ='订单/索引';

模型仅提取行

控制器

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');    
    }


推荐答案

得出答案。因为它不是从数据库中提取行,而是从数组中使用块,所以每页必须为1,因为一个块= 10行。

Worked out the answer. As it isn't pulling rows from the database, instead it's using chunks from the array, per page needed to be one, as one chunk = 10 rows.

$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; 

最终还是放弃了这种方法,并使用数据表来操纵数据并执行分页。

Ended up ditching this method anyway and used datatables to manipulate the data and perform the pagination.

这篇关于Codeigniter 3-来自数组的分页-链接未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆