thinkphp basic additions and deletions of the operation example Tutorial, thinkphp example Tutorial
This paper introduces the basic operation of thinkphp, which is the most commonly used in the development of thinkphp project, and has very important application value. Now the complete example code to share with you, I hope we can help. Specific as follows:
One, table aoli_user field settings:
Table Aoli_user has the following main fields:
ID Username Password Createtime createip
Second, view template part
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: {$vo [' Createip ']} Delete edit
2. User Edit Template:
The aoli/home/tpl/default/user/edit.html page code is as follows:
Second, action part:
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 (' delete succeeded '); }else{$this->error (' delete failed '); }}//Add function Add () {Load (' extend '); if ($_post[' password ']!=$_post[' Repassword ') {$this->error (' two times password inconsistent '); } $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 succeeded, return to Superior page '); }else{$this->error (' User registration failed, return to Superior page '); }}else{$this->error ($user->geterror ()); } }//Display the user's modifier function edit () {$user =m (' user '); $id = (int) $_get[' id ']; $list = $user->where ("id= $id")->find (); $this->assign (' data ', $list); $this->assign (' title ', ' Show user edit information '); $this->display (); }//write update data to database function update () {$user =m (' user '); $user->password=md5 ($user->password); if ($user->create ()) {if ($insertid = $user->save ()) {$this->success (' Update succeeded, number of rows affected '. $insertid); }else{$this->error (' update failed '); }}}}?>
Interested readers can be debugged in the project to run the example described in this article, in order to deepen the understanding of the thinkphp additions and deletions of the operation, convenient for future projects in the flexible use.
thinkphp framework under different modules of the change and delete permissions how to set
You can consider RBAC.
A thinkphp additions and deletions to check and change
http://www.bkjia.com/PHPjc/868238.html www.bkjia.com true http://www.bkjia.com/PHPjc/868238.html techarticle thinkphp Basic additions and deletions of the operation example Tutorial, thinkphp example Tutorial This article describes thinkphp basic additions and deletions to check the operation, is the most commonly used in the development of thinkphp Project Basic operation, ...