Get the App
SLTechnology News&Howtos  ›  Development  › 

How to dynamically set the automatic completion and automatic verification function of ThinkPHP3.1

Shulou Source: shulou.com Published: 2022-06-03 18:00:21 10月03日 Update

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!

Tags: Dynamic validation method model property function content function more version knowledge rule practicality consistency achievement next two code variable can be passed through Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Docker Microsoft Shulou Technology