Php 为什么不显示分页链接?
我是PHP Codeigniter的新手。我正在尝试在我的网页中应用分页,因为我使用了以下代码Php 为什么不显示分页链接?,php,codeigniter,pagination,Php,Codeigniter,Pagination,我是PHP Codeigniter的新手。我正在尝试在我的网页中应用分页,因为我使用了以下代码 $config['base_url'] = base_url().'index.php/admin/pages/index/'; $config['total_rows'] = $this->pages_model->count_pages(); $config['per_page'] = '1'; $config['full_tag_ope
$config['base_url'] = base_url().'index.php/admin/pages/index/';
$config['total_rows'] = $this->pages_model->count_pages();
$config['per_page'] = '1';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$pageData['records']=$this->pages_model->get_pages($config['per_page'],$this->uri->segment(3));
尝试在index.php文件中设置错误报告:
error_reporting(E_ALL);
display_errors(1);
也许你会得到一些错误,让你知道哪里出了问题。你有没有包括分页库
$this->load->library('pagination')代码>如果只有一条记录,它不会显示分页。您的行总数的值是多少
如果您希望分页以其他方式进行,则必须扩展库并重新制作create_links()
,或者在web上找到一个已创建的扩展,该扩展更适合您的需要
这是加载分页库后在控制器中创建分页的代码。
分页库可以作为$this->load->library(“分页”)加载到构造函数或函数中代码>
现在在视图文件中,编写此文件以创建链接
echo $links;
你在什么地方错过了echo吗?我已经写了echo,但也没有变化!codeigniter中只有一个index.php。它在您的根目录中您是否已将“$pageData['records']”传递到您的查看页面?您确定在$pageData['records']
中有值吗。试试看pirnt\r($pageData['records')
;在控制器中,如果出现值,请通过打印($records)
在查看页面中尝试此操作;是的,我肯定。它已通过,但问题是$total_row和$per_page在Pagingnation类中保持不变
$config = array();
$config["base_url"] = "///your url";
$config["total_rows"] = $this->user->record_count();
$config["per_page"] = 1;//may vary
$config["uri_segment"] = 3;//may vary based on url segments
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$this->session->set_userdata('page',$page);
$this->session->set_userdata('per_page',$config["per_page"]);
$data["sposts"] = $this->user->post($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->load->view('post_view',$data);
echo $links;