1、控制器
<?php
namespace app\index\controller;
use app\model\User;
use think\facade\View;
use think\facade\Db; //查询必须引入的Db
use app\BaseController; //必须引入的base
class Haha extends BaseController //继承base
{
public function index() //index方法
{
// 在调用方法之前,先实例化数据表
//$bannerModel=new BannerModel;
// 调用数据表Banner里面的getBanners方法
//$result=$bannerModel->getBanners();
// 打印结果
// print($result);exit();
return view();//输出视图
}
public function chaxun()
{
$id=$this->request->get('id');//接收get
$result=Db::table('cd_agent')->where('id',$id)->find();//查询一条数据数据表的id及get过来的id
//dump($result);
//return json($result); //输出josn
//return view();
View::assign($result); //以字段名作为变量调用
return View::fetch(); ///渲染
}
}
2、html查询表单
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>首页</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="__PUBLIC__/static/js/plugins/layui/css/layui.css" media="all">
<!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
</head>
<body>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<div class="layui-container">
<div class="layui-row">
<div class="layui-col-xs12 layui-col-md8">
<div class="grid-demo grid-demo-bg1">
<form class="layui-form" action="/index/haha/chaxun" method="get">
<div class="layui-form-item">
<label class="layui-form-label">输入框</label>
<div class="layui-input-block">
<input type="text" name="id" required lay-verify="required" placeholder="请输入id" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
</form>
<script>
//Demo
layui.use('form', function(){
var form = layui.form;
//监听提交
form.on('submit(formDemo)', function(data){
layer.msg(JSON.stringify(data.field));
return false;
});
});
</script>
</div>
</div>
</div>
</div>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<!-- 注意:如果你直接复制所有代码到本地,上述 JS 路径需要改成你本地的 -->
</body>
</html>
3、结果显示html
编号:{$id}</br>
姓名:{$name}</br>
身份证号码:{$shenfenzhaoma}</br>
用户头像:{$yonghutouxiang}</br>
积分:{$jifen}
4、如果assign(user)
View::assign('user', $user);
则视图层调用则user.
{$user.name}
{$user.email}