Table of Contents
Practical points of curd application in Thinkphp
Home Backend Development PHP Tutorial Practical points of curd application in Thinkphp_PHP tutorial

Practical points of curd application in Thinkphp_PHP tutorial

Jul 13, 2016 am 09:59 AM
thinkphp main practical application article Main points

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. ...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Practical tips for converting full-width English letters into half-width form Practical tips for converting full-width English letters into half-width form Mar 26, 2024 am 09:54 AM

Practical tips for converting full-width English letters into half-width forms. In modern life, we often come into contact with English letters, and we often need to input English letters when using computers, mobile phones and other devices. However, sometimes we encounter full-width English letters, and we need to use the half-width form. So, how to convert full-width English letters to half-width form? Here are some practical tips for you. First of all, full-width English letters and numbers refer to characters that occupy a full-width position in the input method, while half-width English letters and numbers occupy a full-width position.

The role and practical application of arrow symbols in PHP The role and practical application of arrow symbols in PHP Mar 22, 2024 am 11:30 AM

The role and practical application of arrow symbols in PHP In PHP, the arrow symbol (->) is usually used to access the properties and methods of objects. Objects are one of the basic concepts of object-oriented programming (OOP) in PHP. In actual development, arrow symbols play an important role in operating objects. This article will introduce the role and practical application of arrow symbols, and provide specific code examples to help readers better understand. 1. The role of the arrow symbol to access the properties of an object. The arrow symbol can be used to access the properties of an object. When we instantiate a pair

How to Undo Delete from Home Screen in iPhone How to Undo Delete from Home Screen in iPhone Apr 17, 2024 pm 07:37 PM

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

From beginner to proficient: Explore various application scenarios of Linux tee command From beginner to proficient: Explore various application scenarios of Linux tee command Mar 20, 2024 am 10:00 AM

The Linuxtee command is a very useful command line tool that can write output to a file or send output to another command without affecting existing output. In this article, we will explore in depth the various application scenarios of the Linuxtee command, from entry to proficiency. 1. Basic usage First, let’s take a look at the basic usage of the tee command. The syntax of tee command is as follows: tee[OPTION]...[FILE]...This command will read data from standard input and save the data to

See all articles