在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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
