无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了ThinkPHP基本的增删查改操作,是ThinkPHP项目开发中最常用的基础操作,有着十分重要的应用价值。现将完整的实例代码与大家分享,希望能对大家有所帮助。具体如下:
一、表aoli_user字段设置:
表aoli_user主要有以下几个字段:
id username password createtime createip
二、view模板部分
1.用户首页模板:
aoli/Home/Tpl/default/User/index.html页面代码如下:
<form action="__URL__/add" method="post"> 用户名:<input type="text" name="username" /><br /> 密码:<input type="password" name="password" /><br /> 重复密码:<input type="repassword" name="repassword" /><br /> <input type="submit" value="注册" /> </form> <volist name="alist" id="vo"> <li><span>ID:</span>{$vo['id']}<span>用户名:</span>{$vo['username']}<span>注册ip:</span>{$vo['createip']}<a href="__URL__/del/id/{$vo['id']}">删除</a> <a href="__URL__/edit/id/{$vo['id']}">编辑</a></li> </volist>
2.用户编辑模板:
aoli/Home/Tpl/default/User/edit.html页面代码如下:
<form action="__URL__/update" method="post"> 用户名:<input type="text" name="username" value="{$data['username']}" /><br /> 密码:<input type="password" name="password" value="{$data['password']}" /><br /> IP:<input type="text" name="createip" value="{$data['createip']}" /><br /> 时间:<input type="text" name="createtime" value="{$data['createtime']}" /><br /> <input type="hidden" value="{$data['id']}" name="id" /> <input type="submit" value="更新" /> </form>
二、action部分:
aoli/Home/Lib/Action/UserAction.class.php页面如下:
class UserAction extends Action { function index(){ $user=M('user'); $list=$user->field(array('id','username','createip'))->select(); $this->assign('title','thinkphp视频演示'); $this->assign('alist',$list); $this->display(); } //删除 function del(){ $user=D('user'); if($user->delete($_GET['id'])){ $this->success('删除成功'); }else{ $this->error('删除失败'); } } //增加 function add(){ Load('extend'); if($_POST['password']!=$_POST['repassword']){ $this->error('两次密码不一致'); } $user=D('user'); if($vo=$user->create()){ $user->password=md5($user->password); $user->createtime=time(); //$user->createip=$_SERVER[]; $user->createip=get_client_ip(); if($user->add()){ $this->success('用户注册成功,返回上级页面'); }else{ $this->error('用户注册失败,返回上级页面'); } }else{ $this->error($user->getError()); } } //显示用户的修改项 function edit(){ $user=M('user'); $id=(int)$_GET['id']; $list=$user->where("id=$id")->find(); $this->assign('data',$list); $this->assign('title','显示用户编辑信息'); $this->display(); } //将更新数据写入数据库 function update(){ $user=M('user'); $user->password=md5($user->password); if($user->create()){ if($insertid=$user->save()){ $this->success('更新成功,受影响的行数为'.$insertid); }else{ $this->error('更新失败'); } } } } ?>
感兴趣的读者可以在项目中调试运行一下本文所述实例,以加深对ThinkPHP增删查改操作的理解,方便在以后的项目中加以灵活运用。
标签:
ThinkPHP,增删查改,操作
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]
- 庄锭欣 ELKIE《没有你的未来》[FLAC/分轨][36MB]
- TchaikovskySwanLake,Op.20柴可夫斯基天鹅湖(2013)SACD[Hi-Res]
- 24bit达人艺典《琴歌终极版》整轨WAV+CUE
- 黑鸭子.2005-《发烧DSD》柏菲[WAV分轨]
- 群星.1990-电影看板·人间道【宝丽金】【WAV+CUE】
- 周殷廷.2024-TO.WHOM.IT.MAY.CONCERN【环球】【FLAC分轨】