我正在对搜索功能进行分页,但每次点击页面中的分页链接时,它都不再有效。我认为因为在您点击第2页或下一页后,form_validation现在为假。
这是我的代码:
Controller:employee.php
public function search($start=0){
$this->load->library('pagination');
$this->load->library('form_validation');
$this->form_validation->set_rules('position', 'Position', 'trim');
$this->form_validation->set_rules('status', 'Status', 'trim');
if($this->form_validation->run() == FALSE){
$this->index();
}
else
{
if(($this->session->userdata('user_id')!="")&&($this->session->userdata('user_pos')=="administrator")){
$config['base_url'] = base_url().'employee/search';
$config['total_rows'] =$this->emp_model->getall_useraccounts();
$config['per_page'] = 10;
$config['num_links'] = 4;
$config["uri_segment"] = 3;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['pages'] = $this->pagination->create_links();
$this->load->model('emp_model');
$data['search'] = $this->emp_model->search_2(10,$start);
$data['view'] = $this->emp_model->get_posts();
$this->load->view("include/header_admin.php");
$this->load->view("user_accounts_search.php",$data);
}
else{
$this->index();
}
}
}
模特:emp_model.php
public function getall_useraccounts(){
$this->db->select('*');
$this->db->from('users');
$query=$this->db->get();
return $query->num_rows();
}
__
public function search_2($num,$start){
$position=$this->input->post('position');
$status=$this->input->post('status');
$this->db->select('*');
$this->db->from('users');
if($position!='*'){
$this->db->where('position',$position);
}
if($status!='*'){
$this->db->where('status',$status);
}
$this->db->limit($num, $start);
$query = $this->db->get();
return $query->result_array();
}
观看次数:user_accounts_search.php
<script type="text/javascript">
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
<div id="wrapper">
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
City Environmental Management Office
</h1>
<ol class="breadcrumb">
<li class="active">
<i class="fa fa-users"></i> Employees User Accounts
</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-lg-12 text-center">
<div class="panel panel-default">
<div class="panel-body" style="overflow: scroll;">
<div id="printableArea">
<table class="table table-striped table-bordered table-condensed table-hover">
<tr><?php echo form_open("employee/search"); ?>
<th>PICTURE</th>
<th>NAME</th>
<th>USERNAME</th>
<th>EMAIL</th>
<th><div><b>POSITION</b>
<select name="position" class="form-control">
<option value="*"><?php echo "ALL";?></option>
<option value="administrator"><?php echo "Administartor";?></option>
<option value="encoder"><?php echo "Encoder";?></option>
<option value="enforcer"><?php echo "Enforcer";?></option>
?>
</select>
</div></th>
<th>STATUS
<select name="status" class="form-control">
<option value="*"><?php echo "ALL";?></option>
<option value="1"><?php echo "Active";?></option>
<option value="0"><?php echo "Deactive";?></option>
?>
</select>
</th>
<th>ACTION <br>
<input type="submit" class="btn btn-success" value="Submit" /></th>
<?php echo form_close(); ?>
<?php
foreach($search as $viewview){
$user_stats=$viewview['status'];
$user_id=$viewview['user_id'];
$image_name=$viewview['image_name'];
if($user_stats=='0'){
$color="danger";
}
else{
$color="success";
}
?>
<tr class='<?php echo $color;?>'>
<?php
echo "<td>";
if($image_name!=''){
?>
<img src="<?php echo base_url()?>uploads/<?php echo $image_name;?>" alt="pic" width="100" height="100">
<?php
}
else{
?>
<img src="<?php echo base_url() ?>uploads/default.png" alt="pic" width="100" height="100">
<?php
}
echo "</td>";
echo "<td>".$viewview['lname'].", ".$viewview['fname']." ".$viewview['mname']."</td>";
echo "<td>".$viewview['username']."</td>";
echo "<td>".$viewview['email']."</td>";
echo "<td>".$viewview['position']."</td>";
if($viewview['status']==0){
echo "<td>"."DEACTIVE"."</td>";
}
else{
echo "<td>"."ACTIVE"."</td>";
}
?>
<td>
<ul style="list-style: none;">
<li><a href="<?php echo base_url() ?>employee/passwordupdateemp/<?php echo $user_id?>" class="btn btn-primary btn-xs" role="button">CHANGE PASSWORD</a></li>
<li><a href="<?php echo base_url() ?>employee/emailupdateemp/<?php echo $user_id?>" class="btn btn-primary btn-xs" role="button">CHANGE EMAIL</a></li>
<li><a href="<?php echo base_url() ?>employee/usernameupdateemp/<?php echo $user_id?>" class="btn btn-primary btn-xs" role="button">CHANGE USERNAME</a></li>
<li><a href="<?php echo base_url() ?>employee/update_emp_user/<?php echo $user_id?>" class="btn btn-info btn-xs" role="button">UPDATE</a></li>
<?php if($user_stats==0){?>
<li><a href="<?php echo base_url() ?>employee/stat_activate/<?php echo $user_id?>" class="btn btn-success btn-xs" role="button">ACTIVATE</a></li>
<?php
}
else if($user_stats==1){?>
<li><a href="<?php echo base_url() ?>employee/stat_deactivate/<?php echo $user_id?>" class="btn btn-danger btn-xs" role="button">DEACTIVATE</a></li>
<?php
}?>
</ul>
</td>
<?php
echo "</tr>";
}
?>
</table>
</div>
</div>
<br>
</div>
<?php echo $pages;?>
<br>
<input type="button" onclick="printDiv('printableArea')" value="Print" class="btn btn-success"/>
<br>
</div>
</div>
</table>
</div>
</div><!-- /.container-fluid -->
</div>
谢谢你!
答案 0 :(得分:1)
更改此代码
$this->load->view("include/header_admin.php");
$this->load->view("user_accounts_search.php",$data);
应该是
$this->load->view("header_admin");
$this->load->view("user_accounts_search",$data);