是否可以在读取文件上对视图进行分页。我有一个包含10万个号码的联系人文件。当我在数组中得到它如何应用分页?
控制器:
<?php
$reseller_dnc_phone_arr=array();
if(@file_exists('resources/'.$this->session->userdata['HP']
['memberId'].'/dnc_list.inc')){
$reseller_dnc_phone_arr=@json_decode(@file_get_contents('resources/'.$this->session->userdata['HP']['memberId'].'/dnc_list.inc'));
}
$data['reseller_dnc_phone_arr']=$reseller_dnc_phone_arr;
$data['view_content']='import-dnc-list';
$this->load->view('include/content',$data);
?>
我如何获得限制记录数?
答案 0 :(得分:2)
如果您已在数组中提取数据。您可以使用array_slice来限制记录并将其传递给视图
<?php
$data['array_u_got'] = $array_u_got;
//Pagination - Config as you wish.
$this->load->library("pagination");
$config = array();
$config["base_url"] = base_url() . "controller_path";
$config["total_rows"] = count($data['array_u_got']);
$config["per_page"] = 20;
$config['num_links'] = 5;
$config["uri_segment"] = 3;
$config['use_page_numbers'] = FALSE;
//Pagination Styling
$config['full_tag_open'] = '<div class="dataTables_paginate paging_simple_numbers" id="datatable_paginate"><ul class="pagination">';
$config['full_tag_close'] = '</ul></div>';
$config['num_tag_open'] = '<li class="paginate_button page-item">';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="paginate_button page-item active"><a class="page-link">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li class="paginate_button page-item previous">';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li class="paginate_button page-item next">';
$config['next_tag_close'] = '</li>';
$config['attributes'] = array('class' => 'page-link');
$config['first_link'] = 'First';
$config['prev_link'] = 'Prev';
$config['last_link'] = 'Last';
$config['next_link'] = 'Next';
$config['first_tag_open'] = '<li class="paginate_button page-item">';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li class="paginate_button page-item">';
$config['last_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
//Results to be Passed to the views
$data['results'] = array_slice($data['array_u_got'], $page, $config["per_page"]);
//Pagination Output
$data["links"] = $this->pagination->create_links();