The thinkphp framework allows you to add and display data.

Source: Internet
Author: User
Tags add time

The thinkphp framework allows you to add and display data.

Recent Essays will be written from the use of the thinkPHP framework. Well, I will not talk much about thinkPHP. The following is a dry product.
This article will focus on the use of thinkPHP framework to add data to the database and display the two features on the web page.
Purpose: add data on the add page and display the data on the lists page. (Note: The thinkphp framework occupies the listfield, because the file name must be named like list.html)
Expected page:

 

The following describes how to implement the MVC Architecture Design Model.
First, use the form submission method to implement the V view. The Code is as follows:

<Form role = "form" method = "post" action = "_ MODULE _/Admin/User/doAdd"> <div class = "input-group"> <span class = "input-group-addon"> use  User  Name: </span> <input type = "text" class = "form-control" placeholder = "" name = "username"> </div> <div class = "input-group "> <span class =" input-group-addon "for =" inputWarning1 "> real name: </span> <input type = "text" class = "form-control" placeholder = "" id = "input" name = "realname"> </div> <div class = "input-group"> <span class = "input-group-addon"> mobile phone number: </span> <input type = "text" class = "form-control" placeholder = "" name = "telphone"> </div> <div class = "input-group "> <span class =" input-group-addon "> Email: </span> <input type = "text" class = "form-control" placeholder = "" name = "email"> </div> <div class = "input-group "> <span class =" input-group-addon "> Add time: </span> <input type = "text" class = "form-control" placeholder = "2014-05-22" name = "resgistertime"> </div> <div class = "input- group "> <span class =" input-group-addon "> set the password: </span> <input type = "text" class = "form-control" placeholder = "123456" name = "password"> </div> <div class = "input- group "> <span class =" input-group-addon "> confirm the password: </span> <input type = "text" class = "form-control" placeholder = "123456" name = "repassword"> </div> <div class = "input- group "> <button type =" submit "class =" btn-primary ">  Save </button> </div> </form>

Next is the M mode section. My current understanding of this section is to seriously add data legitimacy and give error messages. The implementation code is as follows:

<? Phpnamespace Admin \ Model; use Think \ Model; class AdminUsersModel extends Model {public $ _ validate = array ("username", "require", "username cannot be blank "), array ("realname", "require", "Real name cannot be blank"), array ("password", "require", "password cannot be blank "), array ("repassword", "require", "Confirm Password cannot be blank"), array ("telphone", "require", "phone cannot be blank "), array ("email", "require", "Mailbox cannot be blank"), array ("resgistertime", "require", "registration time cannot be blank "));}

Finally, the pure logic C controller part. The implementation code is as follows:

Public function add () {$ this-> display ();} public function doAdd () {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 (" failed to add! ");}}

The above is the entire implementation process. I hope it will be helpful for everyone's learning.
ThinkPHP Reference Manual: http://document.thinkphp.cn/manual_3_2.html

Author: orange time

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.