Add administrator functionality with thinkphp framework

Source: Internet
Author: User
Tags add time

Recently due to busy mid-term and final exam did not write a new essay, but also in the heart of the struggle to take the postgraduate examination, until yesterday finally pain determined, only suddenly feel enlightened.

As the teacher left the curriculum design work using thinkphp framework frequently, a few recent essays will be from the use of the thinkphp framework pen, good, nonsense not much to say, the following is dry.

This article will be presented around the use of the thinkphp framework to add data to a database and display both features in a Web page.

Purpose: To display on the lists page after adding data to the Add page (note: Because the thinkphp framework already occupies the list field, you must not use the name "List.html" in the name of the file)

Expected page:

The following is implemented using the MVC architecture design pattern

The first is to implement the V-View section with the form submission, with the following code:

<form role= "form" method= "POST" action= "__module__/admin/user/doadd" > <divclass= "Input-group" > <spanclass= "Input-group-addon" >  User  Name:</span> <input type= "text"class= "Form-control" placeholder= "" name= "username" > </div> <divclass= "Input-group" > <spanclass= "Input-group-addon" for= "InputWarning1" > real name:</span> <input type= "text"class= "Form-control" placeholder= "" id= "input" name= "Realname" > </div> <divclass= "Input-group" > <spanclass= "Input-group-addon" > Mobile number:</span> <input type= "text"class= "Form-control" placeholder= "" Name= "Telphone" > </div> <divclass= "Input-group" > <spanclass= "Input-group-addon" > E-mail:</span> <input type= "text"class= "Form-control" placeholder= "" name= "email" > </div> <divclass= "Input-group" > <spanclass= "Input-group-addon" > Add time:</span> <input type= "text"class= "Form-control" placeholder= "2014-05-22" name= "Resgistertime" > </div> <divclass= "Input-group" > <spanclass= "Input-group-addon" > Set password:</span> <input type= "text"class= "Form-control" placeholder= "123456" name= "password" > </div> <divclass= "Input-group" > <spanclass= "Input-group-addon" > Confirm password:</span> <input type= "text"class= "Form-control" placeholder= "123456" name= "Repassword" > </div> <divclass= "Input-group" > <button type= "Submit"class= "Btn btn-primary" > &nbsp;&nbsp;  Save &nbsp;&nbsp;</button> </div> </form>

Next is the M-mode section, where the individual's current understanding of this part is used to severely add data to the legality and give error hints. The implementation code is as follows:

<?phpnamespace Admin\model; UseThink\model;classAdminusersmodelextendsModel { Public $_validate=Array (        Array("username", "require", "User name cannot be empty"),Array("Realname", "Require", "real name cannot be empty"),Array("Password", "Require", "Password cannot be empty"),Array("Repassword", "Require", "Confirm password cannot be empty"),Array("Telphone", "Require", "phone cannot be empty"),Array("email", "Require", "Mailbox cannot be empty"),Array("Resgistertime", "Require", "registration time cannot be empty")    );}

Finally is the pure logic C Controller part, the implementation code is as follows:

 Public functionAdd () {$this-display ();} Public functionDoadd () {if(!is_post) {        Exit("Bad request!"); }    $adminUsersModel= D ("Adminusers"); if(!$adminUsersModel-Create ()) {        $this->error ($adminUsersModel-GetError ()); }    if($adminUsersModel-Add ()) {                                  $this->success ("added successfully! ", U (" Admin/user/lists ")); }    Else{        $this->error ("Add failed! "); }    }

The above is the entire implementation process.

Links thinkphp Reference Manual: Http://document.thinkphp.cn/manual_3_2.html

Add administrator functionality with thinkphp framework

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.