您好,欢迎访问一九零五行业门户网

Thinkphp中的curd应用实用要点

这篇文章主要介绍了thinkphp中的curd应用实用要点并附上了简单的示例,是篇非常不错的文章,这里推荐给大家。
这个主要闲的没事给大家写一下curd的具体应用,,当然这里边主要讲curd,我做的是用户的增删改查,没有用三大自动
首先
复制代码 代码如下:
class indexaction extends action {
public function index(){
header(“content-type:text/html; charset=utf-8″);
$user=m(‘user');
$list=$user->select();
$this->assign(‘user',$list);
$this->display();
}
显示所有用户 ,首页做的注册
复制代码 代码如下:
form action=”__url__/add” method=”post”>
用户名
密码
用户名:
密码:
注册ip:
注册时间:
删除
更新
然后就是我们的删除方法 很简单 思路是这样的我们获取id删除这个id的就可以了
复制代码 代码如下:
if($user->where(‘$_get[‘id']')->delete())
{
$this->success(‘删除成功');
}
这样就可以了
添加用户的方法
复制代码 代码如下:
$user=m(‘user');
if($user->create()){
$user->cip=get_client_ip();
$user->ctime=time();
$user->password=md5(‘password');
if($user->add($data)){
$this->success(‘用户注册成功','/admin.php/index/edit');
}else{
$this->error($user->geterror());
}
}else{
$this->error(geterror());
}
更新用户是这样的 我们根据id选择用户 输出这个用户的信息
复制代码 代码如下:
$user=m(‘user');
$id=(int)$_get[‘id'];
$user=m(‘user');
$list=$user->where(“id=$id”)->find();
$this->assign(‘list',$list);
$this->display();
然后更新 用户更简单了 就一个save
复制代码 代码如下:
$user=m(‘user');
if($user->create()){
$user->ctime=time();
if($user->save()){
$this->success(‘更新成功');
}
}else{
$this->error(‘失败');
}
这样就结束了 这几部分就能完成用户的增删改查 其实简单 功能就是我们自己添加的了 譬如
我们去论坛就有登陆多少次 怎么完成的 其实一个setinc就能解决登陆一次+1这样输出登陆
次数就可以了
今天先说到这里
其它类似信息

推荐信息