TP5.1 分页(带参数传递)

控制器代码

    public function index(){
    	
		$sotitle=input('sotitle');
		$sotype=input('sotype');
		$this->assign('sotype',$sotype);
		$this->assign('sotitle',$sotitle);
		
				if($sotitle){
					//模糊查询
				    if($sotype=="name" || $sotype==""){
				        $where = [  
				                ['name', 'like', "%".$sotitle."%"],  
				            ]; 
				    }else{  
				            $where[$sotype] = $sotitle;  
				    }  
				  
				}  

        //$rs=Db::name('admin')->where($where)->order(['id'=>'desc'])->paginate(1,false,['query' => $where]);
        $rs = Db::name('admin')->order(['id'=>'desc'])->paginate(1);
		$page = $rs->render();			
		$this->assign('page', $page);
		$this->assign('rs',$rs);
        return $this->fetch();
    }

不带参数:

$rs = Db::name('admin')->order(['id'=>'desc'])->paginate(1);

带参数传递:

$rs=Db::name('admin')->where($where)->order(['id'=>'desc'])->paginate(10,false,['query' => request()->param()]);

['query' => request()->param()],有多少个参数传递都会自动给你增加上,不用一个一个参数这样子写的(->paginate(10,false,['query' => ['cate_id'=>$cate_id], ['keyword'=>$keyword]]);  )



模板:


  {volist name="rs" id="rs"}
            <tr>
		      <td>{$rs.id}</td>
		      <td>{$rs.id}</td>
		      <td>{$rs.name}</td>
		      <td>{$rs.name}</td>
              <td>
                {if condition="$rs['img'] neq ''"}
                <img style="float:left;" src="/Uploads/{$rs.img}" width="25px" height="25px">
                {else /}
                暂无上传头像
                {/if}
              </td>
		      <td>{$rs.time}</td>
		    </tr>
  {/volist}

{$page|raw}


CSS分页样式

<style>
/*分页*/
.pagination {}
.pagination li {display: inline-block;margin-right: -1px;padding: 5px;border: 1px solid #e2e2e2;min-width: 20px;text-align: center;}
.pagination li.active {background: #009688;color: #fff;border: 1px solid #009688;}
.pagination li a {display: block;text-align: center;}
</style>

猜你喜欢

转载自blog.csdn.net/haibo0668/article/details/80805802