首页 > 开发 > Php > 正文

thinkphp框架实现数据添加和显示功能

2020-02-21 21:06:28
字体:
来源:转载
供稿:网友

最近的几篇随笔将都从thinkPHP框架的使用上着笔,好了,废话不多说,下面是干货。
 这篇文章将围绕采用thinkPHP框架 向数据库中添加数据 和 在网页中显示 这两项功能进行展示。
目的:在add页添加数据后在lists页进行显示(注意:由于thinkPHP框架已经将list字段占用,因此在文件命名时不得使用形如“list.html”的命名方式)
预期页面:    

 

下面就利用MVC架构设计模式对其进行实现
首先利用表单提交方式实现V视图部分,代码如下:

<form role="form" method="post" action="__MODULE__/Admin/User/doAdd">         <div class="input-group"> <span class="input-group-addon">用<img src="__PUBLIC__/end/images/em.png" alt="" width="6" height="20">户<img src="__PUBLIC__/end/images/em.png" alt="" width="6" height="20">名:</span>          <input type="text" class="form-control" placeholder="" name="username">         </div>         <div class="input-group "> <span class="input-group-addon" for="inputWarning1">真实姓名:</span>          <input type="text" class="form-control" placeholder="" id="input" name="realname">         </div>         <div class="input-group"> <span class="input-group-addon">手机号码:</span>          <input type="text" class="form-control" placeholder="" name="telphone">         </div>         <div class="input-group"> <span class="input-group-addon">电子邮箱:</span>          <input type="text" class="form-control" placeholder="" name="email">         </div>         <div class="input-group"> <span class="input-group-addon">添加时间:</span>          <input type="text" class="form-control" placeholder="2014-05-22" name="resgistertime">         </div>        <div class="input-group"> <span class="input-group-addon">设置密码:</span>          <input type="text" class="form-control" placeholder="123456" name="password">         </div>        <div class="input-group"> <span class="input-group-addon">确认密码:</span>          <input type="text" class="form-control" placeholder="123456" name="repassword">         </div>         <div class="input-group">          <button type="submit" class="btn btn-primary ">   保<img src="__PUBLIC__/end/images/em.png" alt="" width="20" height="20">存  </button>         </div>        </form> 

接下来是M模式部分,个人目前对这一部分的理解是    用来严重添加数据的合法性和给出错误提示   。实现代码如下:

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表