【发布时间】:2016-05-13 16:44:58
【问题描述】:
我有一个文件列表,我设法在表格上显示这些文件。但是,我意识到,过了一会儿,这些文件会挤满一页。有没有办法给它们分页?我已经在另一个页面中进行了分页,但使用了数据库。我正在使用 Codeigniter。
这是我的观点
<table class="table">
<thead>
<tr>
<th>NRIC</th>
<th>Product</th>
<th>Policy Number</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach($data as $row): ?>
<tr data-url="<?php echo $row['url']; ?>" data-policyno="<?php echo $row['policyno']; ?>">
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['product']; ?></td>
<td><?php echo $row['policyno']; ?></td>
<td><input type="button" class="retrievedoc" value="View"/></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
我的控制器
function index()
{
$this->load->helper('directory');
$this->load->library('pagination');
$this->load->model('statement');
$map = directory_map('./assets/data/');
$nric = $this->session->userdata('nric');
$count=0;
$config = array();
$config['base_url']=site_url('user/statements/index');
$config['total_rows']=$count;
$config['per_page']=5;
$this->pagination->initialize($config);
$data['data']['result'] = $this->statement->retrieve($nric);
$data['data']['links'] = $this->pagination->create_links();
$this->load->view('includes/user/header');
$this->load->view('user/statements',$data);
$this->load->view('includes/user/footer');
}
型号
public function retrieve($nric)
{
$count=0;
$map = directory_map('./assets/data/');
foreach($map as $row)
{
$separate = explode('_',trim($row,".pdf"));
if($nric == $separate[0])
{
$count++;
$data['data'][] = array(
'firstname' => $separate[0],
'product' => $separate[1],
'policyno' => $separate[2],
'url'=> base_url().'assets/data/'.$row
);
}
}
return $data;
}
我附上了一张我得到的图片
【问题讨论】:
-
我添加了一个带有文件分页的答案,如果你愿意,你可以测试一下
-
这是什么 $this->session->userdata('nric'); var_dump 结果呢?
标签: php codeigniter pagination