onestopweb 阅读(151) 评论(0)

application\index\controller\Data.php

<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Data extends Controller
{
    public function index($id=1)
    {
        $pagesize = 3;//显示每页的条数
        $pagebegin = ($id-1) * $pagesize;//从哪里开始显示
        $list = Db::query("select * from think_data LIMIT $pagebegin, $pagesize");
        $this->assign('list', $list);
        $this->assign('count', count($list));
        $this->assign('title', '显示列表');
        return $this->fetch('list');
    }
}

 

application\index\view\Data

<!-- header.html: -->
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>[title]</title>
<link rel="stylesheet" href="/static/base.css">
</head>
<body>

<!-- list.html: -->
{include file="data/header" title="$title" /}
<h2>用户列表({$count})</h2> 
{volist name="list" id="data2" }
<ul>
<li>ID:{$data2.id}
<li>姓名:{$data2.name}<br/>
<li>状态:{$data2.status}<br/>
</ul>
{/volist}
{include file="data/footer" /}

<!-- footer.html: -->
<p>底部信息</p>
</body>
</html>

 

application\route.php

<?php
return [
    // 全局变量规则定义
    '__pattern__'         => [
        'id'    => '\d+',
    ],
    'data'            => 'index/data/index',
    'data/index'      => 'index/data/index',
    'data/:id'        => 'index/data/index',
];

 

效果图:

 

 

 

 

 

 

  • 大小: 8.5 KB