Php Codeigniter分页链接不工作。显示404页。
这是我第一次做分页。除了1 2 3…一切正常。。。。链接我的观点的一部分。数据库的结果也显示得很好。但是,每当我点击2,就会看到一个404页面 我的视图链接: 当我点击2: 我的控制器:Php Codeigniter分页链接不工作。显示404页。,php,codeigniter,pagination,Php,Codeigniter,Pagination,这是我第一次做分页。除了1 2 3…一切正常。。。。链接我的观点的一部分。数据库的结果也显示得很好。但是,每当我点击2,就会看到一个404页面 我的视图链接: 当我点击2: 我的控制器: public function index(){ $this->load->model('model_users'); //--------------------Pagination---------------------- $this->l
public function index(){
$this->load->model('model_users');
//--------------------Pagination----------------------
$this->load->library('pagination');
$config['base_url'] = base_url().'site/index'; ;
$config['total_rows'] = $this->db->get('posts')->num_rows();
$config['uri_segment'] = 3;
$config['per_page'] = 10;
$this->pagination->initialize($config);
$pag = $this->db->order_by("post_id", "desc")->get('posts', $config['per_page'], $this->uri->segment(3));
$table_data_home['allposts'] = $pag->result();
//------------end pagination-------------------------
$this->load->view('my_site',$table_data_home);
}`
以下是我的看法:
<?php
foreach($allposts as $posts){
$title = $posts->post_title;
$name = $posts->name;
$categories = $posts->category;
$post = $posts->post;
$pic = $posts->pic;
$time = $posts->time;
$post_id = $posts->post_id;
?>
<div id="allsinglepost"> <a href="<?php echo site_url('site/full_post'); ?>?post_id=<?php echo $post_id ?>">
<h3><?php echo $title;?></h3>
</a>
<hr class="post_inside_hr">
<h6><b>Written By :</b> <?php echo $name ;?></h6>
<h6><b>Date:</b>
<?php echo substr($time,0,10).'; Time: '.substr($time,11,12); ?>
</h6>
<hr class="post_inside_hr">
<div id="post_description">
<p><?php echo substr($post,0,200) ;?> ........</p>
</div>
</div>
<hr id="postbreakline">
<?php } ?>
<!--The upper part will be a FOREACH for posts-->
<!-- pagination part -->
<?php
echo $this->pagination->create_links();
?>
作者:
日期:
谁能告诉我哪里出了问题?我被困在这里了 在
站点
控制器中创建你的索引
方法,如下所示
public function index(){
$this->load->model('model_users');
//--------------------Pagination----------------------
$this->load->library('pagination');
$config['base_url'] = site_url('site/index');
$config['total_rows'] = $this->db->get('posts')->num_rows();
$config['uri_segment'] = 3;
$config['per_page'] = 10;
$this->pagination->initialize($config);
$pag = $this->db->order_by("post_id", "desc")->get('posts', $config['per_page'], $this->uri->segment(3));
$table_data_home['allposts'] = $pag->result();
//------------end pagination-------------------------
$this->load->view('my_site',$table_data_home);
}
错误出现在
$config['base_url']=base_url().'site/index'代码>这行。查看文件正常更改此$config['base_url']=base_url().'site/index'代码>作为$config['base_url']=site_url('site/index')代码>哇,现在可以工作了。谢谢D@RejoanulAlam:让你的评论成为一个anwser,否则这篇文章就不会有任何意义sense@ZahidulIslamSuzon如果这能解决你的问题,那么你可以接受我的回答。谢谢