Home > Backend Development > PHP Tutorial > Practical points of curd application in Thinkphp_PHP tutorial

Practical points of curd application in Thinkphp_PHP tutorial

WBOY
Release: 2016-07-13 09:59:28
Original
759 people have browsed it

Practical points of curd application in Thinkphp

This article mainly introduces the practical points of curd application in Thinkphp and attaches simple examples. It is a very good article. Recommended to everyone here.

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

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

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.

The code is as follows:


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

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

That’s it

How to add users

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 a user is like this: We select the user based on the ID and output the user's information

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

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

This is it. These parts can complete the user's addition, deletion, modification and query. In fact, it is simple. The functions are added by ourselves, such as

How many times have we logged in to the forum? How is it done? In fact, one setInc can solve the problem of logging in once. 1 This way the login is output

Just a few times

That’s all for today

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975899.htmlTechArticlePractical Points of Curd Application in Thinkphp This article mainly introduces the practical points of curd application in Thinkphp and attaches A simple example, this is a very good article, and I recommend it to everyone. ...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template