七里八里 发表于 2023-7-15 07:31:51

Thinkphp5分页后携带参数跳转传递功能实现

问题:

我在tp框架中写了一个图书详情分页的,代码如下:public function verify_details(){
         $sell_order_num=input('sell_order_num');
      $res=DB::table('verif')->where(["sell_order_num"=>$sell_order_num])->paginate(10);
      // 模板变量赋值
      $this->assign('list',$res);
      $this->assign('sell_order_num',$sell_order_num);
      return $this->view->fetch('Index/verify_details');
    }前端模板通过以下代码 <div class="list-page"> {$list->render()}</div>完成了分页显示能用,但是如何才能实现携带数据sell_order_num传递到verify_details方法中去进行下次检索呢?这个问题我也不会,于是我问了GPT3.5,成功解决

解决办法-它的回答:

可以在分页链接中添加参数,将sell_order_num数据传递到verify_details方法中。具体实现方法如下:在模板中修改分页链接,添加sell_order_num参数:
<div class="list-page"> {$list->appends(['sell_order_num' => $sell_order_num])->render()}</div>在verify_details方法中获取sell_order_num参数(不变):
public function verify_details(){
    $sell_order_num = input('sell_order_num');
    $res = DB::table('verif')->where(["sell_order_num"=>$sell_order_num])->paginate(10);
    // 模板变量赋值
    $this->assign('list',$res);
    $this->assign('sell_order_num',$sell_order_num);
    return $this->view->fetch('Index/verify_details');
}这样就可以在分页时携带sell_order_num数据传递到verify_details方法中了。
测试成功可以携带订单号参数进行翻页

到此这篇关于Thinkphp5分页后携带参数进行跳转传递的文章就介绍到这了,更多相关Thinkphp5分页携带参数跳转内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

来源:https://www.jb51.net/program/2907771bs.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: Thinkphp5分页后携带参数跳转传递功能实现