ThinkPHP基本的增刪查改操作執行個體教程,thinkphp執行個體教程
本文執行個體講述了ThinkPHP基本的增刪查改操作,是ThinkPHP項目開發中最常用的基礎操作,有著十分重要的應用價值。現將完整的執行個體代碼與大家分享,希望能對大家有所協助。具體如下:
一、表aoli_user欄位設定:
表aoli_user主要有以下幾個欄位:
id username password createtime createip
二、view模板部分
1.使用者首頁模板:
aoli/Home/Tpl/default/User/index.html頁面代碼如下:
ID:{$vo['id']}使用者名稱:{$vo['username']}註冊ip:{$vo['createip']}刪除 編輯
2.使用者編輯模板:
aoli/Home/Tpl/default/User/edit.html頁面代碼如下:
二、action部分:
aoli/Home/Lib/Action/UserAction.class.php頁面如下:
class UserAction extends Action { function index(){ $user=M('user'); $list=$user->field(array('id','username','createip'))->select(); $this->assign('title','thinkphp視頻示範'); $this->assign('alist',$list); $this->display(); } //刪除 function del(){ $user=D('user'); if($user->delete($_GET['id'])){ $this->success('刪除成功'); }else{ $this->error('刪除失敗'); } } //增加 function add(){ Load('extend'); if($_POST['password']!=$_POST['repassword']){ $this->error('兩次密碼不一致'); } $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('使用者註冊成功,返回上級頁面'); }else{ $this->error('使用者註冊失敗,返回上級頁面'); } }else{ $this->error($user->getError()); } } //顯示使用者的修改項 function edit(){ $user=M('user'); $id=(int)$_GET['id']; $list=$user->where("id=$id")->find(); $this->assign('data',$list); $this->assign('title','顯示使用者編輯資訊'); $this->display(); } //將更新資料寫入資料庫 function update(){ $user=M('user'); $user->password=md5($user->password); if($user->create()){ if($insertid=$user->save()){ $this->success('更新成功,受影響的行數為'.$insertid); }else{ $this->error('更新失敗'); } } }}?>
感興趣的讀者可以在項目中調試運行一下本文所述執行個體,以加深對ThinkPHP增刪查改操作的理解,方便在以後的項目中加以靈活運用。
thinkphp架構不同模組下的增刪改查許可權怎設定
可以考慮RBAC。
一個thinkphp 增刪查改
http://www.bkjia.com/PHPjc/868238.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/868238.htmlTechArticleThinkPHP基本的增刪查改操作執行個體教程,thinkphp執行個體教程 本文執行個體講述了ThinkPHP基本的增刪查改操作,是ThinkPHP項目開發中最常用的基礎操作,...