Thinkphp中的curd应用实用要点
这个主要闲的没事给大家写一下curd的具体应用,当然这里边主要讲curd,我做的是用户的增删改查,没有用三大自动
首先
classIndexActionextendsAction{
publicfunctionindex(){
header(“Content-Type:text/html;charset=utf-8″);
$user=M(‘user');
$list=$user->select();
$this->assign(‘user',$list);
$this->display();
}
显示所有用户,首页做的注册
formaction=”__URL__/add”method=”post”>
用户名<inputtype=”text”name=”username”>
密码<inputtype=”text”name=”password”>
<inputtype=”submit”value=”提交”>
</form>
<volistname=”user”id=”vo”>
用户名:<inputname=”username”value=”<{$vo.username}>”>
密码:<inputname=”password”value=”<{$vo.password}>”>
注册IP:<inputname=”cip”value=”<{$vo.cip}>”>
注册时间:<inputname=”ctime”value=”<{$vo.ctime}>”>
<ahref=”__URL__/del/id/<{$vo.id}>”>删除</a>
<ahref=”__URL__/edit/id/<{$vo.id}>”>更新</a>
<br>
</volist>
然后就是我们的删除方法很简单思路是这样的我们获取ID删除这个ID的就可以了
if($user->where(‘$_GET[‘id']')->delete())
{ $this->success(‘删除成功'); }