Home > php教程 > php手册 > body text

Thinkphp中的curd应用实用要点,thinkphpcurd

WBOY
Release: 2016-06-13 09:17:28
Original
973 people have browsed it

Thinkphp中的curd应用实用要点,thinkphpcurd

这个主要闲的没事给大家写一下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这样输出登陆

次数就可以了

今天先说到这里

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!