In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "ThinkPHP3.1 how to dynamically set automatic completion and automatic verification function". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Before ThinkPHP 3.1, if you need to set automatic validation or automatic completion, you must define it in the model, or set the property dynamically through the setProperty method, but the disadvantage of doing so is that it is not convenient to change and adjust dynamically.
ThinkPHP3.1 version adds auto and validate two consecutive operations to the model class, which are used to dynamically set auto-completion and auto-validation rules. They can now be used in Action. The example code is as follows:
$validate = array( array(verify,require, Captcha must!), array(name,, Account name already exists!, 0,unique,1), );$auto = array ( array(password,md5,1,function) , array(create_time,time,2,function), );M(User)->auto($auto)->validate($validate)->create();
The specification of the $auto and $validate variables is consistent with the definition rules of the_auto and_validate attributes of the model class, and function calls can also be supported (due to the limitations of PHP itself, functions cannot be called in the attribute definition of the class).
The auto and validate methods must be called before the create method.
With this improvement, you can instantiate your model class using method M and use dynamic settings to complete automatic validation and completion operations, instead of relying on method D.
"ThinkPHP3.1 how to dynamically set automatic completion and automatic verification function" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.