最近由于忙于期中和期末考试没有写新的随笔了,另外内心也在纠结要不要考研,直到昨天终于痛下决心,才突然间觉得豁然开朗。

  由于做老师留的课程设计作业采用thinkPHP框架频繁,最近的几篇随笔将都从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 "> &nbsp;&nbsp;保<img src="__PUBLIC__/end/images/em.png" alt="" width="20" height="20">存&nbsp;&nbsp;</button>
</div>
</form>

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

<?php
namespace Admin\Model;
use Think\Model; class AdminUsersModel extends Model {
public $_validate = array (
array("username", "require", "用户名不能为空"),
array("realname", "require", "真实姓名不能为空"),
array("password", "require", "密码不能为空"),
array("repassword", "require", "确认密码不能为空"),
array("telphone", "require", "电话不能为空"),
array("email", "require", "邮箱不能为空"),
array("resgistertime", "require", "注册时间不能为空")
);
}

最后是纯粹的逻辑C控制器部分啦,实现代码如下:

public function add(){
$this->display();
}
public function doAdd(){
if (!IS_POST) {
exit("bad request!");
}
$adminUsersModel = D("AdminUsers");
if (!$adminUsersModel->create()) {
$this->error($adminUsersModel->getError());
}
if ($adminUsersModel->add()) {
$this->success("添加成功!",U("Admin/User/lists"));
}
else{
$this->error("添加失败!");
} }

以上就是整个实现过程了。

  友情链接thinkPHP参考手册:    http://document.thinkphp.cn/manual_3_2.html

采用thinkphp框架实现添加管理员功能的更多相关文章

  1. Yourphp是一款完全开源免费的.核心采用了Thinkphp框架

    Yourphp企业网站管理系统,是一款完全开源免费的PHP+MYSQL系统.核心采用了Thinkphp框架,同时也作为开源软件发布.集众多开源项目于一身的特点,使本系统从安全,效率,易用及可扩展性上更 ...

  2. ThinkPHP框架整合phpqrcode生成二维码DEMO

    ThinkPHP框架发展到今天功能已经变得是非常强大了,但是ThinkPHP框架中没有二维码相关的库,因此我们可以通过整合phpqrcode来完成生成二维码的功能.想使用phpqrcode首先就要把p ...

  3. 制作类似ThinkPHP框架中的PATHINFO模式功能(二)

    距离上一次发布的<制作类似ThinkPHP框架中的PATHINFO模式功能>(文章地址:http://www.cnblogs.com/phpstudy2015-6/p/6242700.ht ...

  4. php图像处理(thinkphp框架有相对强大的图像处理功能)

    php图像处理(thinkphp框架有相对强大的图像处理功能) 一.总结 1.php处理图像:php处理图像需要安装外库(gd库) 2.gd库函数可以非常完美的操作图像:安装好库之后,这个库里面的函数 ...

  5. thinkphp框架的相关总结

    参考链接地址:http://gongwen.sinaapp.com/article-205.html 1. 模板中不能使用的标签 {$content} {$i} 2. If标签 如: <if c ...

  6. ThinkPHP框架基础知识一

    ThinkPHP是一个快速.兼容而且简单的轻量级国产PHP开发框架,诞生于2006年初,原名FCS,2007年元旦正式更名为ThinkPHP,遵循Apache2开源协议发布,从Struts结构移植过来 ...

  7. 1 ThinkPHP框架初识

    一.PHP主流框架介绍 主流的框架有laravel.symfony.thinkphp MVC和三层结构 MVC可以说是一种开发模式,三层结构是一种开发习惯,严格来讲,他们两者是完全不同的概念,但是在实 ...

  8. 创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段

    创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段 添加查询功能 本文将实现通过Name查询用户信息. 首先更新GetAll方法以启用查询: public async ...

  9. 使用thinkPHP框架实现删除和批量删除一例【原创】

    本文为作者原创,转载请注明原作者及转载地址. 上一篇讲了如何用thinkPHP框架实现数据的添加,那这一篇就讲一下如何用thinkPHP实现数据的删除和批量删除吧. 预期效果图: 原谅博主对照片的处理 ...

随机推荐

  1. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 44 bytes) in

    最近莫名出现这个错误. 研究一下原因很奇葩呢. 原因:sql获取数据库中数据,取出数据赋给变量,数据太多,超过memory_limit内存设置了. 解决方法:设置memory_limit不建议.优化代 ...

  2. hibernate 使用C3P0数据源

    1.导入jar包: hibernate-release-4.3.5.Final/lib/optional/*.jar 2.增加配置: <!-- 配置 C3P0 数据源 --> <pr ...

  3. Oracle VM Virtual Box 4.3 小巧精悍的虚拟机软件

    https://www.virtualbox.org/wiki/Downloads Download VirtualBox Here, you will find links to VirtualBo ...

  4. 9个使用前必须再三小心的Linux命令

      Linux shell/terminal 命令非常强大,即使一个简单的命令就可能导致文件夹.文件或者路径文件夹等被删除.在一些情况下,Linux 甚至不会询问你而直接执行命令,导致你丢失各种数据信 ...

  5. Android Service 服务(一)—— Service .

    http://blog.csdn.net/ithomer/article/details/7364024 一. Service简介 Service是android 系统中的四大组件之一(Activit ...

  6. js之parentElement属性

    <html> <head> </head> <body> <form name="a "> <table name ...

  7. com.code.servlet

    package com.code.servlet; import java.io.IOException; import java.util.LinkedHashMap; import java.ut ...

  8. C#_wpf_userinput_数据绑定_后台对象改变,界面数据也变化

    <!--MainWindow.xaml--> <Window x:Class="UserStore.MainWindow" xmlns="http:// ...

  9. 【面试题】如何让C语言自动发现泄漏的内存

    1. 题目 改造malloc和free函数,使C语言能自动发现泄漏的内存,在程序退出时打印中遗漏的内存地址和大小. 2. 思路 用一个链表来记录已经分配的内存地址.在malloc时,把分配的内存地址和 ...

  10. Android(java)学习笔记130:ProgressBar使用的

    首先我们看例程如下: 1.main.xml文件如下: <?xml version="1.0" encoding="utf-8"?> <Line ...