采用thinkphp框架实现添加管理员功能
最近由于忙于期中和期末考试没有写新的随笔了,另外内心也在纠结要不要考研,直到昨天终于痛下决心,才突然间觉得豁然开朗。
由于做老师留的课程设计作业采用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 "> 保<img src="__PUBLIC__/end/images/em.png" alt="" width="20" height="20">存 </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框架实现添加管理员功能的更多相关文章
- Yourphp是一款完全开源免费的.核心采用了Thinkphp框架
Yourphp企业网站管理系统,是一款完全开源免费的PHP+MYSQL系统.核心采用了Thinkphp框架,同时也作为开源软件发布.集众多开源项目于一身的特点,使本系统从安全,效率,易用及可扩展性上更 ...
- ThinkPHP框架整合phpqrcode生成二维码DEMO
ThinkPHP框架发展到今天功能已经变得是非常强大了,但是ThinkPHP框架中没有二维码相关的库,因此我们可以通过整合phpqrcode来完成生成二维码的功能.想使用phpqrcode首先就要把p ...
- 制作类似ThinkPHP框架中的PATHINFO模式功能(二)
距离上一次发布的<制作类似ThinkPHP框架中的PATHINFO模式功能>(文章地址:http://www.cnblogs.com/phpstudy2015-6/p/6242700.ht ...
- php图像处理(thinkphp框架有相对强大的图像处理功能)
php图像处理(thinkphp框架有相对强大的图像处理功能) 一.总结 1.php处理图像:php处理图像需要安装外库(gd库) 2.gd库函数可以非常完美的操作图像:安装好库之后,这个库里面的函数 ...
- thinkphp框架的相关总结
参考链接地址:http://gongwen.sinaapp.com/article-205.html 1. 模板中不能使用的标签 {$content} {$i} 2. If标签 如: <if c ...
- ThinkPHP框架基础知识一
ThinkPHP是一个快速.兼容而且简单的轻量级国产PHP开发框架,诞生于2006年初,原名FCS,2007年元旦正式更名为ThinkPHP,遵循Apache2开源协议发布,从Struts结构移植过来 ...
- 1 ThinkPHP框架初识
一.PHP主流框架介绍 主流的框架有laravel.symfony.thinkphp MVC和三层结构 MVC可以说是一种开发模式,三层结构是一种开发习惯,严格来讲,他们两者是完全不同的概念,但是在实 ...
- 创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段
创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段 添加查询功能 本文将实现通过Name查询用户信息. 首先更新GetAll方法以启用查询: public async ...
- 使用thinkPHP框架实现删除和批量删除一例【原创】
本文为作者原创,转载请注明原作者及转载地址. 上一篇讲了如何用thinkPHP框架实现数据的添加,那这一篇就讲一下如何用thinkPHP实现数据的删除和批量删除吧. 预期效果图: 原谅博主对照片的处理 ...
随机推荐
- HDU 5500 Reorder the Books 贪心
Reorder the Books Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- 递归循环JSON
using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary ...
- [Bootstrap] 2. class 'row' & 'col-md-x' & 'col-md-offset-x'
Usually when desgin a web page, we think building the page in grid. Bootstrap can help us to do that ...
- java_jdbc_spring框架查询操作简例
1.添加commons-dbcp-1.4,commons-logging,commons-pool-1.2//线程池,commons.collections-3.2.1.jar,spring.jar ...
- C#_datatable_读取
private void button5_Click(object sender, EventArgs e) { string 价格编号 = txtnum.Text; if (价格编号!= " ...
- swfupload详细参数
SWFUpload的初始化与配置 首先,在页面中引用SWFUpload.js ,如<script type=”text/javascript” src=”http://www.swfupload ...
- 【转】Git代码提交最佳实践
GIT Commit Good Practice The following document is based on experience doing code development, bug ...
- the first assignment of software testing
Github ID: bzdwdmzjsmff Github address: https://github.com/bzdwdmzjsmff alternative article: Increa ...
- [置顶] c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date'
c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date' ...
- [转]Oracle字符串拼接的方法
本文转自:http://www.blogjava.net/liuwuping12064915/archive/2011/06/27/353096.html 和其他数据库系统类似,Oracle字符串连接 ...