简体   繁体   English

Code Igniter分页404错误

[英]Code Igniter pagination 404 error

I am having problems with CodeIgniter pagination module. 我在使用CodeIgniter分页模块时遇到问题。

When I go to click on the links I get a 404 error. 当我点击链接时,我收到404错误。 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. 据我了解,我可能是不正确的,但是确定偏移量的URI段似乎未在我的控制器的索引函数中读取,并且代码点火器实际上正在将其作为控制器中的函数进行查找,因此抛出了404当它找不到它时。

I have googled around and checked on the forum to find a solution but have not had any success. 我已经google搜索并在论坛上查找了解决方案,但没有取得任何成功。 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(); 

Well its going to fail first off because of your base_url: 那么它会因为你的base_url而首先失败:

$config['base_url'] = 'http://example.com/index.php/test/page/';

You need the full path, altho I am just guessing here as you don't provide the URL that is throwing the 404. 您需要完整的路径,尽管我只是在这里猜测,因为您没有提供抛出404的URL。

Notes on pagination here: http://codeigniter.com/user_guide/libraries/pagination.html 有关分页的注意事项,请访问: http : //codeigniter.com/user_guide/libraries/pagination.html

Your base_url is not correct: 你的base_url不正确:

//should be something like this
$config['base_url'] = base_url().'/controllername/functionname/';

See: http://codeigniter.com/user_guide/libraries/pagination.html 请参阅: http : //codeigniter.com/user_guide/libraries/pagination.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM