Home >Backend Development >PHP Tutorial >Practical points of curd application in Thinkphp, thinkphpcurd_PHP tutorial

Practical points of curd application in Thinkphp, thinkphpcurd_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:10:12772browse

Practical points for curd application in Thinkphp, thinkphpcurd

This time I have nothing to do but write about the specific application of curd. Of course, I mainly talk about curd here. What I do is the addition, deletion, modification and checking of users, and I don’t use the three major automatics

First of all

Copy code The code is as follows:

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();
}

Show all users, registered on the homepage

Copy code The code is as follows:

form action=”__URL__/add” method=”post”>
Username
Password



Username:”>
Password:”>
Register IP:”>
Registration time:”>
”>Delete
”>Update



Then there is our deletion method. It is very simple. The idea is like this. We can get the ID and delete the ID.

Copy code The code is as follows:

if($user->where(‘$_GET[‘id’]’)->delete())

{
$this->success(‘Deletion successful’);
}

That’s it

How to add users

Copy code The code is as follows:

$user=M(‘user’);
if($user->create()){
$user->cip=get_client_ip();
$user->ctime=time();
$user->password=md5(‘password’);
if($user->add($data)){
$this->success('User registration successful','/admin.php/index/edit');
}else{
$this->error($user->getError());
}
}else{
$this->error(getError());
}

Updating users is like this. We select the user based on ID and output the user’s information

Copy code The code is as follows:

$user=M(‘user’);
$id=(int)$_GET[‘id’];
$user=M(‘user’);
$list=$user->where(“id=$id”)->find();
$this->assign(‘list’,$list);
$this->display();

Then updating makes it easier for users. Just save

Copy code The code is as follows:

$user=M(‘user’);
if($user->create()){
$user->ctime=time();
if($user->save()){
$this->success(‘Update successful’);
}
}else{
$this->error(‘Failure’);
}

That’s it. These parts can complete the user’s addition, deletion, modification and query. In fact, the simple functions are just added by ourselves, such as

How many times have we logged in to the forum? How is it done? In fact, a setInc can solve the problem of logging in once + 1 so that the login is output

Just a few times

That’s all for today

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/937089.htmlTechArticlePractical points of curd application in Thinkphp. Thinkphpcurd is mainly free to write about the specific application of curd for everyone. Of course The main topic here is curd. What I do is user addition, deletion, modification and query...
Statement:
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