在ThinkPHP3.1版本之前,如果需要设置自动验证或者自动完成,必须定义在模型中,或者通过setProperty方法动态设置属性来完成,但是这样做的缺点是不太方便动态改变和调整 。
ThinkPHP3.1版本在模型类中增加auto和validate两个连贯操作,用于动态设置自动完成和自动验证规则,现在可以在Action中使用,示例代码如下:
$validate = array( array(verify,require,验证码必须!), array(name,,帐号名称已经存在!,0,unique,1), ); $auto = array ( array(password,md5,1,function) , array(create_time,time,2,function), ); M(User)->auto($auto)->validate($validate)->create();
其中$auto和$validate变量的规范和模型类的_auto和_validate属性的定义规则一致,而且还可以支持函数调用(由于PHP本身的限制,在类的属性定义中不能调用函数) 。
auto和validate方法必须在create方法之前被调用 。
通过这一改进,你完全可以通过M方法实例化模型类后使用动态设置完成自动验证和自动完成操作,不必再依赖D方法了 。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
