Three major automated PHP tutorials in thinkPHP

Source: Internet
Author: User
The three major automatic versions in thinkPHP. The three major automatic classUserModelextendsModel {protected $ _ validatearray in thinkPHP (the array needs to be written below. An array is a validation rule array (validation field, validation of the three major automatic thinkPHP

Class UserModel extends Model {
Protected $ _ validate = array (

// You also need to write the array below. An array is a validation rule.
// Array ('verification field', 'verification rule', 'error message', 'verification condition', 'additional rule', 'verification time '),
// Verification field: the name of the form field to be verified, or some auxiliary fields in the form, such as the verification code, additional code, and repeated passwords.
// Verification rules. The verification rules must be used together with the additional rules.
// Error message: if an error occurs, what error message is thrown to notify the user?
// Verification conditions: 0, 1, 2 ()
// Additional rules:
// Regex enables the primary regular expression for verification. you can write a regular expression in the verification rules. (the first brother connected to the forum to download the regular expression video from Master Gao,
// Second, thinkphp features are strong. he mails some regular expressions for us. third, some common regular expressions have been prepared on the Internet)
// The function is verified using the function. the function name time must be specified in the preceding verification rule.
// Callback is a callback. it will find a member method in the current UserModel.
// Confirm verifies that the two fields in the form are equal.
// Equal checks whether the base is equal to a value
// Whether in is in a certain range of verification rules requires writing an array
// Check whether the unique verification is unique. The system will query the database based on the current field value to determine whether the same value exists.
//
// If you use some common built-in regular expressions, you only need to write the error message,
// The require field must verify that the email verification email url is the number of the currency number that verifies the url address
// Verification time: the time when the database operation is verified
// 1 verify the Model: MODEL_INSERT when adding data
// Verify Model: MODEL_UPDATE only when editing
// 3 verify Model: MODEL_BOTH in all cases
//
Array ("user_name", "require", "the user name must be filled in! "),
Array ("user_name", "6, 12", "the user name must be between 6 and 12", 0, "length "),
Array ("real_name", "require", "enter a real name! "),
Array ("password", "require", "the password must be entered! "),
Array ("password", "8, 12", "the password must be between 8 and 12 characters", 0, "length "),
Array ("rePassword", "require", "repeated passwords must be entered! "),
Array ("password", "rePassword", "the two passwords are inconsistent", 0, "confirm "),
Array ("email", "require", "email is required "),
Array ("email", "email", "incorrect email format! ", 1 ),
Array ("verify", "require", "verification code required "),
Array ("code", "checkCode", "verification code input error", 0, "callback "),
);


Protected $ _ auto = array (

// Array ('fill field', 'fill content', 'fill condition', 'Add rule ');
// Fill field: this field can be a field in the form or in the database. It can also be some auxiliary fields
// Fill in the content and use it with additional rules
// Fill condition. values 1, 2, and 3 correspond to "add", "edit", and "Model: MODEL_INSERT" in all cases (the default parameter is "fill" when "add)
// Additional rules, function callback, field (filled with other fields), indicating that a value of other fields can be obtained here
// String, string to fill. This is the default option automatically completed by thinkphp.

Array ("password", "md5", 3, "function "),
Array ("age", "deal_int", 3, "callback "),
);


Protected $ _ map = array (
"Username" => "user_name", // different thinkPHP versions may be different. Note that they correspond to the fields in $ _ validate.
"Realname" => "real_name", // 'is to write the fields in the form before' => 'is written to the back, and the real fields in the data table are written to the back ',
);

Protected function deal_int ($ data ){
Return (int) $ data;
}
Protected function checkCode ($ data ){
If (md5 ($ _ POST ['code'])! = $ _ SESSION ['verify ']) {
Return false;
}
Return true;
}
}

Using class UserModel extends Model {protected $ _ validate = array (// you need to write an array again below. An array is a validation rule // array ('verification field', 'verification...

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.