The thinkphp framework is used to add administrators.
Recently, I was not writing a new essay in the busy period and the final exam, and I was also struggling to take a postgraduate entrance exam. It was not until yesterday that I finally made up my mind that I suddenly felt suddenly enlightened.
Due to the frequent thinkPHP framework used in the Course Design assignments left by instructors, the most recent Essays will be written from the use of thinkPHP framework. Well, I will not talk much about the thinkPHP framework. Here is what we will do.
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: <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 "> & nbsp; & nbsp; save storage & nbsp; & nbsp; </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.
ThinkPHP Reference Manual: http://document.thinkphp.cn/manual_3_2.html