我试图将分页添加到我的Codeigniter项目中,但是每次我收到为foreach()提供无效参数的错误时。有人可以帮我吗。 控制器中的代码
public function staff()
{
$this->load->library('pagination');
$config['base_url'] = 'staff';
$config['total_rows'] = $this->staff_model->record_count();
$config['per_page'] = 4;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['data'] = $this->staff_model->get_staff($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('templates/header',$data);
$this->load->view('pages/staff',$data);
$this->load->view('templates/footer');
$this->load->helper('url');
}
我认为代码
foreach ($staff as $staff_item){ ?>
<div class="col-md-3 col-sm-6 col-xs-12 animate-box text-center">
<div class="doctor border border-secondary" style="background-color: white; border-style: solid; height: 450px;">
<a href="<?php echo site_url('welcome/viewstaff/'.$staff_item['slug']); ?>"> <img src="<?php echo base_url().'uploads/'.$staff_item['pic_file'] ?>" class="img-fluid" style="width: 253px; height: 250px"></a>
<div class="desc">
<h3 ><a href="<?php echo site_url('welcome/viewstaff/'.$staff_item['slug']); ?> " style="color: green"><?php echo $staff_item['title']; ?> <?php echo $staff_item['name']; ?></a> <i class="fa fa-external-link" aria-hidden="true"></i></h3>
<p ><?php echo $staff_item['department']; ?></p>
<h3><?php echo $staff_item['designation']; ?></h3>
</div>
</div>
</div>
答案 0 :(得分:0)
使用此代码
public function staff()
{
$this->load->library('pagination');
$config['base_url'] = 'staff';
$config['total_rows'] = $this->staff_model->record_count();
$config['per_page'] = 4;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
//here I changed data with staff
$data['staff'] = $this->staff_model->get_staff($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('templates/header',$data);
$this->load->view('pages/staff',$data);
$this->load->view('templates/footer');
$this->load->helper('url');
}