问题:
我在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方法中了。
测试成功可以携带订单号参数进行翻页