ThinkPHP_实现简单分页

ThinkPHP文档参考地址:https://www.shouce.ren/api/view/a/12704

模型方法实现分页
得创建一个model 名字和数据库表 去除前缀后的名字一样
比如 数据库表 叫tp_goods
model名字得叫Goods
数据库表前缀 在database.php里配置
在这里插入图片描述

跳转首页的控制器里:

    public function index()
    {
        //分页查询 每页10条
       $goods = \app\admin\model\Goods::paginate(10);
        return view('index',['g' => $goods]);

    }

index.html 视图页面

 <div class="well">
            <!-- table -->
            <table class="table table-bordered table-hover table-condensed">
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>商品名称</th>
                        <th>商品价格</th>
                        <th>商品数量</th>
                        <th>商品logo</th>
                        <th>添加时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach $g as $item}
                    <tr class="success">
                        <td>{$item.id}</td>
                        <td><a href="javascript:void(0);">{$item.goods_name}</a></td>
                        <td>{$item.goods_price}</td>
                        <td>{$item.goods_number}</td>
                        <td><img src="/static/admin/img/goods01_thumb.jpg"></td>
                        <td>{$item.update_time}</td>
                        <td>
                            <a href="{:url('admin/goods/edit',['id'=> $item.id])}"> 编辑 </a>
                            <a href="#" onclick="if(confirm('确认删除?')) location.href='{:url(\'admin/goods/delete\',[\'id\'=>$item.id])}'"> 删除 </a>
                        </td>
                    </tr>
                    {/foreach}
                </tbody>
            </table>
            <!-- pagination -->
            <div class="">
                {$g->render()}
            </div>
        </div>

关键代码:

在这里插入图片描述

修改分页 样式:

    <style type="text/css">
        .pagination li{list-style:none;float:left;margin-left:10px;
            padding:0 10px;
            background-color:#ffffff;
            border:1px solid #ccc;
            height:26px;
            line-height:26px;
            cursor:pointer;color:#fff;
        }
        .pagination li a{color: #bbafaf;padding: 0;line-height: inherit;border: none;}
        .pagination li a:hover{background-color: #5a98de;}
        .pagination li.active{background-color:#5a98de; color: #ffffff;}
        .pagination li.disabled{background-color: #ffffff;color:gray;}
    </style>

效果图:
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值