Goods.php 控制器
代码如下:
public function index() { $sousuo = input('sousuo'); //创建一个 空数组 用来追加 查询条件 $where = []; if(!empty($sousuo)){ $where['goods_name'] = ['like' , "%$sousuo%"]; } //分页查询 每页10条 flase不是简单分页 参数三:而外url参数 $goods = \app\admin\model\Goods::where($where)->paginate(10,false,['query' => ['sousuo' => $sousuo] ]); return view('admin@goods/index',['g' => $goods]); }
视图 index.html
<div class="well"> <!-- search button --> <form action="{:url('admin/goods/index')}" method="get" class="form-search"> <div class="row-fluid" style="text-align: left;"> <div class="pull-left span4 unstyled"> <p> 商品名称:<input class="input-medium" name="sousuo" value="{$Request.param.sousuo}" type="text"></p> </div> </div> <button type="submit" class="btn">查找</button> <a class="btn btn-primary" href="{:url('admin/goods/create')}">新增</a> </form> </div> <div class="well">