Mac_ThinkPHP_配合bootstrap实现分页

1.首先创建一个model

指定表主键

指定表名

model里的代码

<?php

namespace app\common\model;

use think\Model;

class day3 extends Model
{
    //主键
    protected $pk ="id";
    //表名
    protected $table = "tp_articles";
    
}

2.创建一个对应的controller

对应controller的代码

<?php

namespace app\index\controller;

use think\Controller;

use app\common\model\day3;
use think\Db;
use think\db\Query;
use think\db\Where;

class day3Class extends Controller
{
    //分页方法
    public function page(){
        //查询tp_articles的数据 10条一页
        $data = day3::name("tp_articles")->paginate(10);
        //跳转到view里名字叫page的html页面
        return view("index/page",compact("data"));
    }

}

对应view里的html页面代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>明天会更好</title>
    <link rel="stylesheet" href="/static/css/bootstrap.css"/>
    <link rel="stylesheet" href="/static/css/bootstrap-theme.css"/>
</head>
<body>
    <table class="table table-responsive">
        <thead>
        <tr>
            <th>id</th>
            <th>标题</th>
            <th>描述</th>
            <th>内容</th>
            <th>操作</th>
        </tr>
        </thead>

        {foreach $data as $item}
        <tbody>
        <tr>
            <td>{$item.id}</td>
            <td>{$item.title}</td>
            <td>{$item.desn}</td>
            <td>{$item.body}</td>
            <td>
                <div class="btn-group">
                    <button type="button" class="btn btn-group-xs btn-default">修改</button>
                    <button type="button" class="btn btn-group-xs btn-danger">删除</button>
                </div>
            </td>
        </tr>
        </tbody>
        {/foreach}
    </table>
    {$data|raw}
<script src="/static/jquery.min.js"></script>
    <script src="/static/js/bootstrap.js"></script>
    <script src="/static/js/npm.js"></script>
</body>
</html>

展示效果图👇

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值