This article mainly introduces ThinkPHP's basic addition, deletion, query, and modification operations, which are widely used in ThinkPHP programming, for more information about ThinkPHP, see the examples in this article. ThinkPHP is the most common basic operation in ThinkPHP project development and has very important application values. Now I will share the complete instance code with you, hoping to help you. The details are as follows:
I. table aoli_user field settings:
The aoli_user table has the following fields:
Id username password createtime createip
II. view template
1. user homepage template:
The aoli/Home/Tpl/default/User/index.html page code is as follows:
ID: {$ vo ['id']} user name: {$ vo ['username']} registered ip address: {$ vo ['createip']} delete and edit
2. the user edits the template:
The aoli/Home/Tpl/default/User/edit.html page code is as follows:
II. action:
The aoli/Home/Lib/Action/UserAction. class. php page is as follows:
Class UserAction extends Action {function index () {$ user = M ('user'); $ list = $ user-> field (array ('id', 'username ', 'createip')-> select (); $ this-> assign ('title', 'thinkphp video Demo'); $ this-> assign ('alist ', $ list); $ this-> display () ;}// delete function del () {$ user = D ('user '); if ($ user-> delete ($ _ GET ['id']) {$ this-> success ('deleted successfully ');} else {$ this-> error ('deletion failed');} // add function add () {Load ('extend'); if ($ _ POST ['Pas Sword']! = $ _ POST ['repassword']) {$ this-> error ('inconsistent two passwords ');} $ user = D ('user '); if ($ vo = $ user-> create () {$ user-> password = md5 ($ user-> password); $ user-> createtime = time (); // $ user-> createip =$ _ SERVER []; $ user-> createip = get_client_ip (); if ($ user-> add ()) {$ this-> success ('User registration successful, back to superior page');} else {$ this-> error ('User registration failed, back to superior page ');}} else {$ this-> error ($ user-> getError () ;}// display the user's function edit () {$ user = M ('user'); $ Id = (int) $ _ GET ['id']; $ list = $ user-> where ("id = $ id")-> find (); $ this-> assign ('data', $ list); $ this-> assign ('title', 'show user editor '); $ this-> display () ;}// write the updated data to the database function update () {$ user = M ('user '); $ user-> password = md5 ($ user-> password); if ($ user-> create () {if ($ insertid = $ user-> save ()) {$ this-> success ('update successful, the number of affected rows is '. $ insertid);} else {$ this-> error ('update failed'); }}}?>
Interested readers can call and run the examples described in this article in the project to deepen their understanding of ThinkPHP's addition, deletion, and modification operations, so that they can be used flexibly in future projects.