TP5 搜尋按條件分頁

DanaSwan發表於2018-09-11
public function index()
    {
        $map = [];

        if($this->request->isGet()) {
            $data = $this->request->get();
            if (!empty($data['id'])) {
                $map['id'] = $data['id'];
            }
            
            //模糊查詢
            if (!empty($data['itemname'])) {
                $map['itemname'] = ['like', "%{$data['itemname']}%"];
            }
            $this->assign('map',$map);

        }


        $propList = ($this->prop_model->where($map)->paginate(15,false,['query' => request()->param()]));

        $this->assign('propList',$propList);
        return $this->fetch('index');

    }

直接用render ok 

 <table class="layui-table">
                    <colgroup>
                        <col width="150">
                        <col width="150">
                        <col>
                    </colgroup>
                    <thead>
                    <tr>
                        <th style="width: 30px;">ID</th>
                        <th>道具名稱</th>

                    </tr>
                    </thead>
                    <tbody>
                    {empty name="propList"}
                    <tr colspan="30" style="text-align: center"><span class="">暫無此資料!</span></tr>
                    {else /}
                    {foreach name="propList" item="vo"}
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.itemname}</td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
                <!--分頁-->
                {$propList->render()}

                {/empty}

 

相關文章