Php 分页中未找到CodeIgniter 404错误页
我有问题使CodeIgniter分页时,我点击链接,我得到404页找不到 我在控制器中的代码是Php 分页中未找到CodeIgniter 404错误页,php,codeigniter,pagination,http-status-code-404,Php,Codeigniter,Pagination,Http Status Code 404,我有问题使CodeIgniter分页时,我点击链接,我得到404页找不到 我在控制器中的代码是 class Records extends CI_Controller { public function index() { $this->load->library('pagination'); $config['base_url']= 'localhost/records'; $config['total_row
class Records extends CI_Controller
{
public function index()
{
$this->load->library('pagination');
$config['base_url']= 'localhost/records';
$config['total_rows']= $this->db->get('pages')->num_rows;
$config['per_page']= 2;
$config['num_links']= 5;
$this->pagination->initialize($config);
$data['query'] = $this->db->get('pages',$config['per_page'],$this->uri->segment(2));
$this->load->view('view_header');
$this->load->view('includes/nav_home');
$this->load->view('view_list', $data);
$this->load->view('view_footer');
}
我尝试了不同的uri段,但仍然没有结果?我正在以正确的方式编写代码。我的基本url在配置文件中为空
鉴于我的代码是
<?php
echo $this->session->flashdata('item');
echo '<h4>Lista podataka</h4>';
foreach ($query->result() as $q):
?>
<a href="/z/update/grab/<?php echo $q->id;?>/<?php echo $q->info; ?>"><?php echo $q->info . br() . br()?></a>
<?php
endforeach;
echo $this->pagination->create_links();
?>
据我所知,您无法访问下一页分页?所以我认为这是因为这个
$config['base_url']='localhost/records'代码>
您应该输入完整的url(包括控制器名和函数名),因此
$config['base_url']='localhost/records/index.php/controller_name/function'代码>
在您的uri段中应该$this->uri->segment(3)
尝试更改uri段
$this->load->library('pagination');
$config['base_url']= base_url().'/records/index';
$config['total_rows']= $this->db->get('pages')->num_rows;
$config['uri_segment'] = 3;
$config['per_page']= 2;
$config['num_links']= 5;
$this->pagination->initialize($config);
$data['query'] = $this->db->get('pages',$config['per_page'],$this->uri->segment(3));
有关更多信息,请参见:-基本Url需要
$config['base_url']= 'records/index';
中的基url必须包含用于获取数据的相同函数
它意味着$config['base_url']='localhost/project/records/index' 它的问题是因为我在index()函数中设置了分页,我创建了单独的函数,它可以工作!不是函数问题,你需要使用正确的基URL是的,也许我应该把索引放在前面!这可能是一个错误,因为我在index()函数中设置了分页,创建了一个单独的函数,它可以正常工作!不可以。你应该输入正确的基本url,尝试更改其中的代码,并告诉我是否仍然有错误。我这样做了,并且它的工作函数页面(){$this->load->library('pagination');$config['base\u url']='';$config['total\u rows']=$this->db->get('pages')->num rows;$config['per\u page']=2;$config['num_links']=5;$this->pagination->initialize($config);$this->load->model('Data');$Data['query']=$this->Data->Data_pagination($config['per_page'],$this->uri->segment(3));}你没有其他问题吗?投票给我,如果这有帮助的话,你可以帮我更多的忙吗?我目前在一家公司学习,如果我表现出一些技能,也许他们会雇用我,我是自学php的