代码Igniter分页404错误
我在使用 CodeIgniter 分页模块时遇到问题。
当我点击链接时,出现 404 错误。据我了解,我可能是不正确的,但似乎确定偏移量的 URI 段没有在我的控制器的索引函数内读取,并且代码点火器实际上正在将其作为控制器内的函数来查找,因此抛出找不到时返回 404。
我用谷歌搜索并在论坛上查看以找到解决方案,但没有取得任何成功。如果有人有任何提示或技巧,那就太好了,我已经在下面包含了我的控制器、模型和视图中的相关代码。
//控制器
$this->load->library('pagination');
$config['base_url'] = '/yourhistory/';
$config['total_rows'] = $this->db->get('gallery')->num_rows();
$config['per_page'] = 3;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$data['galleryitems'] = $this->pages_model->get_gallery($config['per_page'], $config['uri_segment']);
$this->load->view('/gallery', $data);
//模型
function get_gallery($limit, $segment)
{
$query = $this->db->get('gallery', $limit, $this->uri->segment($segment));
if ($query->num_rows > 0)
{
foreach($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
//视图
echo $this->pagination->create_links();
I am having problems with CodeIgniter pagination module.
When I go to click on the links I get a 404 error. As I understand and I may be incorrect, but it would seem that the URI segment which determines the offset is not being read inside the index function of my controller and that code igniter is actually looking for this as a function inside the controller hence throwing the 404 when it cant find it.
I have googled around and checked on the forum to find a solution but have not had any success. If anyone has any hints or tips that would be great I have included the relevant code from my controller, model and view below.
//Controller
$this->load->library('pagination');
$config['base_url'] = '/yourhistory/';
$config['total_rows'] = $this->db->get('gallery')->num_rows();
$config['per_page'] = 3;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$data['galleryitems'] = $this->pages_model->get_gallery($config['per_page'], $config['uri_segment']);
$this->load->view('/gallery', $data);
//Model
function get_gallery($limit, $segment)
{
$query = $this->db->get('gallery', $limit, $this->uri->segment($segment));
if ($query->num_rows > 0)
{
foreach($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
//View
echo $this->pagination->create_links();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,由于你的base_url,它首先会失败:
你需要完整的路径,尽管我只是在这里猜测,因为你没有提供引发 404 的 URL。
此处有关分页的注释: http://codeigniter.com/user_guide/libraries/pagination.html
Well its going to fail first off because of your base_url:
You need the full path, altho I am just guessing here as you don't provide the URL that is throwing the 404.
Notes on pagination here: http://codeigniter.com/user_guide/libraries/pagination.html
您的 base_url 不正确:
请参阅:http://codeigniter.com/user_guide/libraries/pagination.html
Your base_url is not correct:
See: http://codeigniter.com/user_guide/libraries/pagination.html