我们需要为一个视图拥有两个不同的分页表,因为客户端想要它。这看起来没有问题,但问题是,当我更改第一个表的页面时,它是可以的。但是,当我将第二张表更改为本页的第二张时,第二页的高亮显示不会亮起。
有什么建议吗?或者在一个视图中有两个分页的任何可能的替代解决方案?
我的配置是:
$data['title'] = 'Dashboard ';
$configPendingDash = array();
$configOpenDash = array();
$configPendingDash["base_url"] = base_url() . "/index.php/Users/dashboard";
$configPendingDash["total_rows"] = $this->Users_model->get_count_pending_applications();
$configPendingDash["per_page"] = 5;
$configPendingDash["uri_segment"] = 3;
$configOpenDash["base_url"] = base_url() . "/index.php/Users/dashboard/".$this->uri->segment(3,0);
$configOpenDash["total_rows"] = $this->Users_model->get_count_open_applications();
$configOpenDash["per_page"] = 5;
$configOpenDash["uri_segment"] = 4;
$configPendingDash['full_tag_open'] = '<div class="pagination">';
$configPendingDash['full_tag_close'] = '</div>';
$configPendingDash['first_link'] = 'First';
$configPendingDash['last_link'] = 'Last';
$configPendingDash['first_tag_open'] = '<li class="page-item"><span class="page-link">';
$configPendingDash['first_tag_close'] = '</span></li>';
$configPendingDash['prev_link'] = '«';
$configPendingDash['prev_tag_open'] = '<li class="page-item"><span class="page-link">';
$configPendingDash['prev_tag_close'] = '</span></li>';
$configPendingDash['next_link'] = '»';
$configPendingDash['next_tag_open'] = '<li class="page-item"><span class="page-link">';
$configPendingDash['next_tag_close'] = '</span></li>';
$configPendingDash['last_tag_open'] = '<li class="page-item"><span class="page-link">';
$configPendingDash['last_tag_close'] = '</span></li>';
$configPendingDash['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$configPendingDash['cur_tag_close'] = '</a></li>';
$configPendingDash['num_tag_open'] = '<li class="page-item"><span class="page-link">';
$configPendingDash['num_tag_close'] = '</span></li>';
$configOpenDash['full_tag_open'] = '<div class="pagination">';
$configOpenDash['full_tag_close'] = '</div>';
$configOpenDash['first_link'] = 'First';
$configOpenDash['last_link'] = 'Last';
$configOpenDash['first_tag_open'] = '<li class="page-item"><span class="page-link">';
$configOpenDash['first_tag_close'] = '</span></li>';
$configOpenDash['prev_link'] = '«';
$configOpenDash['prev_tag_open'] = '<li class="page-item"><span class="page-link">';
$configOpenDash['prev_tag_close'] = '</span></li>';
$configOpenDash['next_link'] = '»';
$configOpenDash['next_tag_open'] = '<li class="page-item"><span class="page-link">';
$configOpenDash['next_tag_close'] = '</span></li>';
$configOpenDash['last_tag_open'] = '<li class="page-item"><span class="page-link">';
$configOpenDash['last_tag_close'] = '</span></li>';
$configOpenDash['cur_tag_open'] = '<li class="page-item active"><a class="page-link" href="#">';
$configOpenDash['cur_tag_close'] = '</a></li>';
$configOpenDash['num_tag_open'] = '<li class="page-item"><span class="page-link">';
$configOpenDash['num_tag_close'] = '</span></li>';
$this->pagination->initialize($configPendingDash);
$data["pendinglink"] = $this->pagination->create_links();
$this->pagination->initialize($configOpenDash);
$data["openlink"] = $this->pagination->create_links();
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$page2 = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data['pending_applications'] = $this->Users_model->get_count_pending_applications($configPendingDash["per_page"], $page);
$data['open_applications'] = $this->Users_model->get_count_open_applications($configOpenDash["per_page"], $page2);
$this->load->view('include/header', $data);
$this->load->view('include/sidetopbar', $data);
$this->load->view('user/dashboard', $data);
我的型号是:
public function get_count_open_applications()
{
if(empty($searchBook))
$this->db->where('col_status', 'OPEN');
$this->db->from($this->tbl_loan_application);
return $this->db->count_all_results();
}
public function get_count_pending_applications()
{
$this->db->where('col_status', 'PENDING');
$this->db->from($this->tbl_loan_application);
return $this->db->count_all_results();
}
public function get_maximum_applications($limit, $start)
{
$this->db->limit($limit, $start);
$this->db->select('*');
$this->db->from($this->tbl_loan_application);
$this->db->where('col_status', 'PENDING');
$this->db->order_by('loan_id','desc');
$query=$this->db->get();
return $query->result();
}
public function get_open_applications($limit, $start)
{
$this->db->limit($limit, $start);
$this->db->select('*');
$this->db->from($this->tbl_loan_application);
$this->db->where('col_status', 'OPEN');
$this->db->order_by('loan_id','desc');
$query=$this->db->get();
return $query->result();
}
我的观点是:
<div class="table-responsive">
<table class="table table-sm table-hover table-bordered">
<thead class="thead">
<?php if(empty($pending_applications)){
echo "<strong>Whoops!</strong> Looks like there's no pending loans as of the moment.";
} else {?>
<tr>
<th scope="col">Name</th>
<th scope="col">Company Code</th>
<th scope="col">Loan Type</th>
<th scope="col">Period</th>
<th scope="col">Borrower ID</th>
<th scope="col">Co-maker</th>
<th scope="col">Loanable</th>
<th scope="col">Terms</th>
<th scope="col">Status</th>
</tr>
<?php } ?>
</thead>
<tbody>
<?php foreach($pending_applications as $row): ?>
<tr>
<th scope="row">
<strong><?php echo $row->col_full_name; ?> </strong><br>
<?php echo $row->col_loan_assignid; ?>
</th>
<td><?php echo $row->col_comp_code; ?></td>
<td><?php echo $row->col_loan_type; ?></td>
<td scope="row">
<?php echo $row->col_dte_application; ?><br><br>
<?php echo $row->col_due_date; ?>
</td>
<td><?php echo $row->col_borrower_id; ?></td>
<td><?php echo $row->col_coMaker_perc; ?></td>
<td><?php echo $row->col_loanable; ?></td>
<td><?php echo $row->col_terms; ?></td>
<td>
<button class="btn btn-secondary btn-xs" data-bs-toggle="modal" data-bs-target="#exampleModal">Pending</button>
<button class="btn btn-link btn-xs">View</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p><?php echo $pendinglink; ?></p>
</div>
创建第一组分页链接时,CodeIgniter将url的页面偏移量值除以配置中的per_page
值,并在内部将其保存为当前页面值。
当您第二次初始化库时,它似乎不会重置当前页面值。由于它已经有了当前页面值,因此不再使用与url的页面偏移量,并将错误的页面标记为";活动的";在第二组分页链接中。
您可以通过为initialize
:的第二次调用手动设置cur_page
来解决此问题
要么将其设置为被认为是";"空";通过php重置页码并强制CodeIgniter再次使用url中的值:$configOpenDash['cur_page'] = 0;
或者,如果这给php8带来了问题,请像前面的问题一样明确设置它:$configOpenDash['cur_page'] = $this->uri->segment(4) ?: -1;