我想调用分页功能,所以我不会厌倦重写我创建的分页代码。在这个问题上,当我调用该函数时,它的功能没有按我想要的那样运行。 分页功能不显示。
这是我的代码:
功能分页:
public function pagination(){
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_link'] = '<i class="fa fa-long-arrow-left"></i>Previous Page';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next Page<i class="fa fa-long-arrow-right"></i>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
}
这是我想要显示分页功能的代码:
public function dataRule(){
if (!empty($this->session->userdata('username'))) {
$row=$this->TabelRule_model->barisRule();
$this->load->library('form_validation');
$config['base_url'] = 'http://localhost/diagnosaKucing/tabelrule';
$config['total_rows'] = $row;
$config['per_page'] = 8;
$this->pagination();
$start=$this->uri->segment(2);
$this->pagination->initialize($config);
$data['rows'] =$row;
$data['tabelrule'] = $this->TabelRule_model->tampilTabelRule($config['per_page'],$start);
$this->load->view('pages/static/header');
$this->load->view('pages/forms/tabelrule',$data);
$this->load->view('pages/static/footer');
}else {
redirect('Login/signin');
}
}
我不想要我的代码:
public function dataRule(){
if (!empty($this->session->userdata('username'))) {
$row=$this->TabelRule_model->barisRule();
$this->load->library('form_validation');
$config['base_url'] = 'http://localhost/diagnosaKucing/tabelrule';
$config['total_rows'] = $row;
$config['per_page'] = 8;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['prev_link'] = '<i class="fa fa-long-arrow-left"></i>Previous Page';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = 'Next Page<i class="fa fa-long-arrow-right"></i>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$start=$this->uri->segment(2);
$this->pagination->initialize($config);
$data['rows'] =$row;
$data['tabelrule'] = $this->TabelRule_model->tampilTabelRule($config['per_page'],$start);
$this->load->view('pages/static/header');
$this->load->view('pages/forms/tabelrule',$data);
$this->load->view('pages/static/footer');
}else {
redirect('Login/signin');
}
}
我得到的结果:pagination
答案 0 :(得分:2)
你的函数没有返回任何内容,它有一个$config
变量,带有局部范围。
你应该这样做:
public function pagination(){
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
...
return $config;
}
然后:
public function dataRule(){
if (!empty($this->session->userdata('username'))) {
$row=$this->TabelRule_model->barisRule();
$this->load->library('form_validation');
$config = $this->pagination();
$config['base_url'] = 'http://localhost/diagnosaKucing/tabelrule';
$config['total_rows'] = $row;
$config['per_page'] = 8;
$start=$this->uri->segment(2);
$this->pagination->initialize($config);
...
等等。