我是 Codeigniter 的新手。这是我在 Codeigniter 的第一次体验。我的分页有问题。我已经尝试了很多在论坛和博客上给出的代码。最后我跟着一个教程,链接:CodeIgniter from Scratch- Day 16 - Displaying & Sorting Tabular Data - Nettuts+
这是我的代码:
用户.php
public function index($offset=0)
{
$limit = 10;
$this->load->model('user_model');
$results = $this->user_model->get_all_users($limit,$offset);
$data['users'] = $results['rows'];
$data['num_results'] = $results['num_rows'];
$this->load->library('pagination');
$config = array();
$config['base_url'] = site_url('admin/user');
$config['total_rows'] = $data['num_results'];
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$date['pagination'] = $this->pagination->create_links();
$data['page_title'] = "List Of Users";
$this->load->view('admin/users', $data);
}
用户模型.php
function get_all_users($limit, $offset)
{
$q = $this->db
->select('user_id,user_email,login_name,phone_num,user_status')
->from('tbl_user')
->limit($limit,$offset);
$ret['rows'] = $q->get()->result();
$q = $this->db
->select('COUNT(*) as count', FALSE)
->from('tbl_user');
$tmp = $q->get()->result();
$ret['num_rows'] = $tmp[0]->count;
return $ret;
}
用户.php
<?php
$this->load->view('includes/header');
$this->load->view('includes/menu-admin');
?>
<div id="container">
<?php if(isset($users)) { ?>
<p><?php $this->load->view('includes/footer'); ?></p>
<table id="users_table" class="board">
<tr>
<th class="blue-gradient">#</th>
<th class="blue-gradient">Email Address</th>
<th class="blue-gradient">Login Name</th>
<th class="blue-gradient">User Status</th>
<th class="blue-gradient">Current Status</th>
</tr>
<?php $count=1; ?>
<?php foreach ($users as $user) { ?>
<tr id="user_<?php echo $user->user_id; ?>" class="darker-on-hover">
<td><?php echo $count; ?></td>
<td><?php echo anchor('admin/profile/view/'.$user->user_id,$user->user_email , 'class="view-profile-details"'); ?></td>
<td><?php echo $user->login_name; ?></td>
<td><?php echo $user->user_status; ?></td>
<td>
<?php echo anchor('admin/user/edit/'.$user->user_id , '<img src="'.base_url().'images/edit.png" title="Edit User"/>'); ?>
<?php echo anchor('admin/user/remove/'.$user->user_id , '<img src="'.base_url().'images/remove.png" title="Remove User"/>', 'class="remove-user-event"'); ?>
</td>
</tr>
<?php $count++; } ?>
</table>
<?php } ?>
<div id="pageNum">
<?php if(strlen($pagination)): ?>
Pages: <?php echo $pagination; ?>
<?php endif; ?>
</div>
</div>
如果我错了,请告诉我?