我想用分页和排序创建搜索功能。但我不知道如何在CodeIgniter中执行此操作。以下是我的控制器功能:
activity_main
以下是查看代码
function view($page = 1,$sort='emp_id',$order='asc'){
$data['title']='View Employee';
$data['active']='Employee';
$search=$this->input->post('search');
$num_rows=$this->employeeModel->empCount();
$config['base_url'] ='employee/view';
$config['total_rows'] = $num_rows;
$config['per_page'] =5;
$this->pagination->initialize($config);
$arr=array(
'limit' =>$config['per_page'],
'start' =>(($page-1) * $config['per_page']),
'sort' =>$sort,
'order' =>$order,
'search' =>$search
);
$data['search']=$search;
$data['empDetails']=$this->employeeModel->getEmp($arr);
($this->input->is_ajax_request())? $this->load->view('ajaxFiles/viewEmp',$data): $this->template->load('templates/template','HR-Admin/viewEmp',$data);
}
以下是我的ajax分页脚本
<form action="<?php echo base_url().'employee/view' ?>" method="GET">
<input type="search" name="search" id="search" value="<?php if(!empty($search)){echo $search;} ?>" placeholder="Search" />
<input type="submit" name="" value="Search" class="btn btn-primary" />
</form>
<table id="emp_table" width="100%" border="1" class="table-condensed table-bordered table-striped table-responsive">
<thead>
<?php if($this->session->userdata('emp_role')=='Admin'){ ?>
<tr>
<form action="<?php echo base_url().'employee/delete'; ?>" name="multiple_delete" method="post" >
<td colspan="10"><input type="submit" name="delete" id="delete" class="btn btn-danger" style="float: right" value="Delete All" /></td>
</tr>
<?php } ?>
<tr class="ajax_request">
<th>#</th>
<th><a href="<?php echo base_url().'employee/view/'.$page_num.'/first_name/'.$order; ?>">Employee Name</a></th>
<th><a href="<?php echo base_url().'employee/view/'.$page_num.'/emp_role/'.$order;?>">Employee Role</a></th>
<th><a href="<?php echo base_url().'employee/view/'.$page_num.'/shift/'.$order; ?>">Employee Shift</a></th>
<th><a href="<?php echo base_url().'employee/view/'.$page_num.'/emp_position_id/'.$order; ?>">Employee Designation</a></th>
<th>Profile Picture</th>
<th>Action</th>
</tr>
</thead>
<tbody id="values">
<?php $cur_page = $this->uri->segment(3) ? intval($this->uri->segment(3)) : 1;
$i = (($cur_page-1) * 5) +1;
foreach($empDetails as $val){ ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo ucfirst($val['first_name']).' '.ucfirst($val['last_name']); ?></td>
<td><?php echo $val['emp_role']; ?></td>
<td><?php echo $val['shift_type']; ?></td>
<td><?php echo $val['position']; ?></td>
<?php if(empty($val['profile_img'])){ ?>
<td><img src="<?php echo base_url().'images/user_image.png'; ?>" alt="Profile Img" width="80px" height="80px" /></td>
<?php } else{ ?>
<td><img src="<?php echo base_url().$val['profile_img']; ?>" alt="Profile Img" width="80px" height="80px" /></td>
<?php } ?>
<td>
<a href="<?php echo base_url().'employee/empProfile/'.$this->encrypt->encode($val['emp_id']); ?>"><button class="btn btn-info">View Profile</button></a>
<a title="Edit" href="<?php echo base_url().'employee/edit/'.$this->encrypt->encode($val['emp_id']); ?>"><button class="btn btn-default"><i class="glyphicon glyphicon glyphicon-pencil"></i></button></a>
<?php if($this->session->userdata('emp_role')=='Admin') { ?>
<a title="Delete" onclick="return confirm_delete()" href="<?php echo base_url().'employee/delete/'.$this->encrypt->encode($val['emp_id']); ?>"><button class="btn btn-default"><i class="glyphicon glyphicon glyphicon-trash"></i></button></a>
<input type="checkbox" name="multi_del[]" id="multi_del" value="<?php echo $val['emp_id']; ?>" />
<?php } ?>
</td>
</tr>
<?php $i++; } ?>
</tbody>
</form>
</table>
<ul class="ajax_request"> <?php echo $this->pagination->create_links(); ?></ul>
任何人都可以帮我这样做吗?
提前致谢。