我需要一个CodeIgniter分页助手。
我一直在努力创造它一周,这是我的代码。我有我的控制器和视图,在视图页面上我有一个表格,我想创建下面的分页是我的代码
控制器
<?php
/* * **MANAGE MEMBERS**** */
function member($param1 = '', $param2 = '', $param3 = '') {
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
if ($param1 == 'create') {
$data['names'] = $this->input->post('names');
;
$data['birthdate'] = $this->input->post('birthdate');
$data['gender'] = $this->input->post('gender');
$data['email'] = $this->input->post('email');
$data['address'] = $this->input->post('address');
$this->db->insert('member', $data);
$member_id = mysql_insert_id();
move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/member_image/' . $member_id . '.jpg');
$this->email_model->account_opening_email('member', $data['email']); //SEND EMAIL ACCOUNT OPENING EMAIL
redirect(base_url() . 'index.php?admin/member/', 'refresh');
}
if ($param1 == 'do_update') {
$data['names'] = $this->input->post('names');
;
$data['birthdate'] = $this->input->post('birthdate');
$data['gender'] = $this->input->post('gender');
$data['email'] = $this->input->post('email');
$data['address'] = $this->input->post('address');
$this->db->where('member_id', $param2);
$this->db->update('member', $data);
move_uploaded_file($_FILES['userfile']['tmp_name'], 'uploads/member_image/' . $param2 . '.jpg');
redirect(base_url() . 'index.php?admin/member/', 'refresh');
} else if ($param1 == 'personal_profile') {
$page_data['personal_profile'] = true;
$page_data['current_member_id'] = $param2;
} else if ($param1 == 'edit') {
$page_data['edit_data'] = $this->db->get_where('member', array(
'member_id' => $param2
))->result_array();
}
if ($param1 == 'delete') {
$this->db->where('member_id', $param2);
$this->db->delete('member');
redirect(base_url() . 'index.php?admin/member/', 'refresh');
}
$page_data['members'] = $this->db->get('member')->result_array();
$page_data['page_name'] = 'member';
$page_data['page_title'] = get_phrase('manage_member');
$this->load->view('index', $page_data);
}
查看
<table id="table" class="table table-bordered table-hover datatable">
<thead>
<tr>
<th><?php echo get_phrase('name'); ?></th>
<th><?php echo get_phrase('birthdate'); ?></th>
<th><?php echo get_phrase('gender'); ?></th>
<th><?php echo get_phrase('email'); ?></th>
<th><?php echo get_phrase('address'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($members_info as $row) { ?>
<tr>
<td><img src="<?php echo $this->crud_model->get_image_url('member', $row['member_id']); ?>" class="img-circle" width="40px" height="40px"></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['birthdate'] ?></td>
<td><?php echo $row['gender'] ?></td>
<td><?php echo $row['email'] ?></td>
<td><?php echo $row['address'] ?></td>
<td>
<a onclick="showAjaxModal('<?php echo base_url(); ?>index.php?modal/popup/edit_member/<?php echo $row['member_id'] ?>');"
class="btn btn-default btn-sm btn-icon icon-left">
<i class="entypo-pencil"></i>
Edit
</a>
<a href="<?php echo base_url(); ?>index.php?admin/member/delete/<?php echo $row['patient_id'] ?>"
class="btn btn-danger btn-sm btn-icon icon-left" onclick="return checkDelete();">
<i class="entypo-cancel"></i>
Delete
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
答案 0 :(得分:1)
在控制器上执行此操作
$this->load->library('pagination');
$config['base_url'] = 'index.php?admin/member/';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$this->pagination->initialize($config);
在视图
上 <?php
echo $this->pagination->create_links();
?>