ThinkPHP basic tutorial on adding, deleting, querying, modifying, and operating instances, thinkphp instance tutorial _ PHP Tutorial

Source: Internet
Author: User
ThinkPHP basic addition, deletion, query, modification, and Operation instance tutorial, thinkphp instance tutorial. ThinkPHP basic instance tutorial for addition, deletion, query, modification, and modification. thinkphp instance tutorial this article describes the basic addition, query, modification, and modification operations of ThinkPHP, which is the most common basic operation in ThinkPHP project development, thinkPHP basic instance tutorial for adding, deleting, querying, and modifying operations, and thinkphp instance tutorial

This article describes the basic addition, query, modification, and deletion operations of ThinkPHP. it 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.


    How to set the add, delete, modify, and query permissions for different modules of the thinkphp framework?

    You can consider RBAC.
     

    Add, query, modify, and delete a thinkphp file


    Examples in this article describes the basic addition, query, modification, and modification operations of ThinkPHP, which is the most common basic operation in ThinkPHP project development ,...

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.