The three major automatic introductions in ThinkPHP and ThinkPHP. ThinkPHP's three major automatic introductions, ThinkPHP's three major introductions, this article describes ThinkPHP's three major automatic introductions in detail and is a very important application for your reference. For example, ThinkPHP's three major automatic introductions and ThinkPHP's three major introductions
This article describes the three major automated ThinkPHP applications in detail and is a very important application for your reference. The details are as follows:
1. Automatic Verification
The format is as follows:
Array ('verification field', 'verification rule', 'error message', 'verification condition', 'additional rule', 'verification time ')
Parameter description:
Verification field: the name of the form field to be verified
Verification rules: must be used together with additional rules
Error prompt: if an error occurs, what kind of error message is thrown to notify the user?
Verification conditions: 0, 1, 2
Additional rules: 1. regex regular expression verification. 2. function verification. 3. callback. 4. confirm. check whether the two fields in the form are the same. 5. check whether the field is equal to a value. 6. whether the in field is in one. scope 7. verify if it is unique
TP encapsulation: The require field must be verified; eamil verification email address; url verification url address; currency; number;
Verification Time: indicates the verification time of the database operation time. when new data is added, Model: MODEL_INSERT is verified. when edited, Model: MODEL_UPDATE is verified. in all cases, Model: MODEL_BOTH is verified;
The aoli/Home/Tpl/default/User/reg.html page is as follows:
The aoli/Home/Lib/Model/UserModel. class. php page is as follows:
<? Phpclass UserModel extends Model {// corresponding database table user protected $ _ validate = array ('username', 'require ', 'username mandatory '), array ('username', 'checklen', 'username is too long or too short ', 0, 'callback'), array ('password', 'require ', 'password required '), array ('repassword', 'require', 'repeated password'), array ('password', 'repassword ', 'Two passwords are inconsistent ', 0, 'confirm'), array ('createtime', 'number', 'You entered not number'), array ('createip ', 'email ', 'invalid email format'),); function checklen ($ da Ta) {if (strlen ($ data)> 15 | strlen ($ data) <5) {return false;} else {return true ;}}?>
The aoli/Home/Lib/Action/UserAction. class. php page is as follows:
<? Php class UserAction extends Action {function reg () {$ this-> display ();} function regadd () {$ user = D ('user '); if ($ user-> create () {if ($ user-> add () {$ this-> success ('registered successfully ');} else {$ this-> error ('registration failed') ;}} else {$ this-> error ($ user-> getError () ;}}}?>
II. automatic completion (automatic filling)
Automatic completion is also a member method in ThinkPHP. it is automatically executed during create.
The rules are as follows:
Array ('fill field', 'fill content', 'fill condition', 'Add rule ');
A simple example is as follows:
Protected $ _ auto = array (// array ('status', '1'), // Set the status field to 1 array ('password ', 'md5', 1, 'Function'), // when the password field is added, make the md5 function process array ('createtime', 'time', 3, 'function'), // write the current timestamp to the create_time field during update );
II. automatic ing (field ing)
Automatic ing: map database fields to aliases, and you can use aliases in the form.
A simple example is as follows:
protected $_map = array( 'name' => 'username', 'pass' => 'password',);
The skills described in this article are helpful for you to learn and use ThinkPHP.
The thinkphp313 function cannot be automatically loaded.
If debugging is enabled immediately, the runtime folder is deleted. if you log on, log out and log on again.
Automatic Verification of thinkphp
You can remove $ this-> error (), and $ User-> getError () can be output. Because you have already shown the above, blocking the subsequent display. The error message is displayed only by getError.
This article describes the three major automated ThinkPHP applications in detail and is a very important application for your reference. For details, see...