Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to the three Automation of ThinkPHP

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the details of the three automatic introductions of ThinkPHP, the content is very detailed, interested friends can refer to, hope to be helpful to you.

I. automatic verification

The format is as follows:

Array ('validation field', 'validation rule', 'error prompt', 'verification condition', 'additional rule', 'validation time')

Parameter description:

Validate fields: need to validate form field names

Validation rules: must be used in conjunction with additional rules

Error tip: if an error occurs, what kind of error prompt is thrown to inform the user

Verification conditions: 0, 1, 2

Additional rules: 1. Regex uses regular validation 2, function uses function validation 3, callback callback 4, confirm verifies whether the two fields in the form are the same 5, whether the verification is equal to a certain value 6, whether the in is in a certain range 7, whether the verification is unique

TP Encapsulation: require field must be verified; eamil verify mailbox; url verify url address; currency currency; number number

Verification time: refers to the verification time of database operation time. Verify Model::MODEL_INSERT; when adding new data, verify Model::MODEL_UPDATE; when editing, verify Model::MODEL_BOTH in all cases.

The aoli/Home/Tpl/default/User/reg.html page is as follows:

User name: password: repeat password: registration time: register IP:

The aoli/Home/Lib/Model/UserModel.class.php page is as follows:

The aoli/Home/Lib/Action/UserAction.class.php page is as follows:

2. Automatic completion (automatic filling)

Autocomplete is also a member method of ThinkPHP, which is automatically executed in create.

The rules are as follows:

Array ('fill field', 'fill content', 'fill condition', 'additional 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 added, / / a pair of password fields make the md5 function handle array ('createtime','time',3,'function') when new, / / a pair of create_time fields are written to the current timestamp when updated)

3. Automatic mapping (field mapping)

Automatic mapping: map the fields of the database to aliases so that aliases can be used in the form.

A simple example is as follows:

Protected $_ map = array ('name' = >' username', 'pass' = >' password',); this is the end of the three automatic introductions about ThinkPHP. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report