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