【问题标题】:Codeigniter pagination issue with uri_segmenturi_segment 的 Codeigniter 分页问题
【发布时间】:2019-05-08 00:58:53
【问题描述】:

这就是我的网址的样子, http://example.com/Admin/uploadQuestionsForSections/1/2(第四段是分页的页码。第三段是id)。问题是,点击分页链接没有提供正确的记录。所有页面显示相同的记录。我在下面提供了分页配置:

$config["uri_segment"] = 4;
$config['base_url'] = base_url().'Admin/uploadQuestionsForSections/'.$this->uri->segment(3).'';
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;

==

但是它不起作用。帮助将不胜感激

【问题讨论】:

  • 您能解释一下如何它不起作用吗?这样可以更轻松地了解您的问题并为您提供帮助。
  • 您好,我的意思是,我可以从 db 看到相同的初始结果集,无论我在哪个页面上都没有关系..
  • 不确定这是否是一个因素,但您始终可以在 base_url() 中包含 controller/method/ 部分......它看起来更干净,您仍然可以稍后添加 3+ 段。以base_url('admin/uploadQuestionsForSections').$this-uri->segment(3).'/'.$this->uri->segment(4); 为例

标签: codeigniter pagination codeigniter-3


【解决方案1】:

试试这个:

$config['base_url'] = base_url($this->uri->uri_string().'/');

【讨论】:

  • 感谢您的回复。我会尽力让你知道..但是,你能解释一下,这到底是做什么的吗?
  • 它是 base_url 的通用解决方案,您不需要每次使用分页时自己写下来,并在其末尾添加一个斜杠,因为您将需要它.. 如果它告诉我工作,如果没有,我们将探讨您可能做错了什么。
  • 那我猜可能不是分页问题,​​可能是您的控制器或模型功能有问题,所以请更新您的问题并向我们展示您的方法!
  • 这是怎么回事:==在控制器中调用方法== $trans_record = $this->Common_model->getData($rowno,$rowperpage,$arrPost,$this->uri- >段(3)); ===在模型中====== public function getData($rowno,$rowperpage,$arrPost="",$sec_id) { $this->db->select('id, qustion'); $this->db->from('gk_questions'); $this->db->WHERE('section_id', $sec_id); if($arrPost){ $this->transactionQuery($arrPost); $this->db->order_by('id','DESC'); $this->db->limit($rowperpage, $rowno); $query = $this->db->get();返回 $query->result_array(); }
猜你喜欢
  • 2011-04-04
  • 1970-01-01
  • 2015-04-27
  • 2017-01-16
  • 1970-01-01
  • 2017-02-21
  • 2014-09-21
  • 2013-04-04
相关资源
最近更新 更多