ThinkPHP基本的增刪查改操作執行個體教程,thinkphp執行個體教程_PHP教程

來源:互聯網
上載者:User

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項目開發中最常用的基礎操作,...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.