【发布时间】:2014-10-03 15:46:03
【问题描述】:
嗨,这可能很明显,但我是分页新手,我认为 CI 的文档真的很垃圾,我期望得到的是一个链接列表,当我点击每个链接列表时,它应该显示我的 3 个 li每页项目,它显示链接列表并且链接有效,但每页没有显示一定数量的结果,有人可以帮助我吗?
我的控制器部分:
public function clist()
{
//load the model that gets a list of clients
$this->load->model('list_model');
//call the function that lists clients and store the return data in a variable
$fields = $this->list_model->listcliname();
//create an array
$data = array();
//assign the data to a key in the array
$data['fields'] = $fields;
//pass the array to view for handling and load the view.
$this->load->library('pagination');
$config['base_url'] = site_url('clientlist/clist');
$config['total_rows'] = 500;
$config['per_page'] = 3;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
$this->load->view('clientlist', $data);
我的观点:
<html>
<head>
<title> client list </title>
<link rel="stylesheet" type="text/css" href="/css/clientlist.css">
<!-- add script to add jquery and add a function that performs a confirm on the event of a click on the delete link. -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.confirmation').on('click', function () {
return confirm('Are you sure?');
});
});
</script>
</head>
<body>
<div id="container">
<?php
foreach($fields as $field) {
?>
<ul>
<li>
<?php echo $field['name']; ?>
</li>
<li>
<?php echo $field['contact']; ?>
</li>
<li>
<form action="clistedit" method="post">
<input type="hidden" name="sub" value="1" />
<input type="hidden" name="UID" value="<?php echo $field['UID']?>">
<button type="submit">edit</button>
</form>
</li>
<li>
<a href="/clientlist/delete/<?php echo $field['UID']; ?>/" class="confirmation">delete</a>
<a href="/clientlist/salelead/<?php echo $field['UID']; ?>/">view lead</a>
</li>
</ul>
<?php
}
?>
</div>
编辑:我是否必须在某处配置正在分页的数据或函数的链接是否可以做到这一点?
【问题讨论】:
-
如何回显'
';打印_r($字段);回声'
';看起来像? -
它打印出我在第 1 页上的每个数组
-
and 2 etc,就像链接指向完全相同的东西,只是没有限制。
-
另外,如果可以的话,我建议从 Codeigniter 转移到 laravel。易于学习和加载的库,让您的生活更轻松。
-
@seanyt123 我知道它的作用,我想知道它的外观:)
标签: php codeigniter hyperlink pagination