【问题标题】:Return to same page in pagination分页返回同一页面
【发布时间】:2018-09-15 12:03:38
【问题描述】:
| Item | Stock | Description | Action 
| Book | 5     | PHP Books   | Edit   
| Pen  | 14    | Gold Pen    | Edit   
| Pen2 | 2     | Silver Pen  | Edit   

|Previous|1|2|**3**|4|5|Next|

我在第 3 页的表格中有一些项目,我想编辑一个项目,当我单击保存数据时,我想返回到该表格并显示相同的页面。

现在,当我点击保存时,我将返回第 1 页

也许你有阅读的参考,或者因为我不知道关键字。

【问题讨论】:

  • 在保存按钮的链接中包含对他们所在页面的引用。
  • 您如何获得您的页码?你能不能像index.php?page=2一样通过GET传递它,那么你所要做的就是$page = $_GET['page']
  • 你可以使用 HTTP_REFERER 吗? $url_to_redirect_after_save = $_SERVER['HTTP_REFERER'] ?? base_url('default/to/page/1');
  • 编辑您的问题,您尝试了哪些代码。

标签: php mysql codeigniter pagination


【解决方案1】:

在表单的隐藏字段中添加页码。

表单提交后,重定向到该页面

页码是您传递给控制器​​函数的参数:public function index($page_nbr = 0)

这是一个例子:

public function index($page_nbr = 0)
{
    $this->load->library('pagination');
    $config['base_url'] = '/users/index/';
    $config['total_rows'] = $this->users_model->count_users();
    $config['per_page'] = 40;
    $this->pagination->initialize($config);
    $data['pagination'] = $this->pagination->create_links();
    $data['current_page_number'] = $page_nbr;
    $this->run('users', $data);     
}

【讨论】:

  • hmm,页码怎么获取?
  • 你的控制器中已经有了它。它应该是您传递给函数的参数
猜你喜欢
  • 1970-01-01
  • 2017-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-11
  • 2013-12-20
  • 2012-09-26
相关资源
最近更新 更多