In TP, we can use the following two methods to create a ing object for a data table (I am currently using)
First: $ test = D ('test ')
Type 2: $ test = new model ('test ')
Although both of them can perform select, insert, delete, and udpate operations on data, there is a big difference in data verification,
Let's take a look at the effect. First, create a testmodel.
CopyCodeThe Code is as follows: Class testmodel extends model {
Protected $ _ validate = Array {
Array ('title', 'require ', 'Enter the title', 1 ),
Array ('content', 'require ', 'Enter the content', 1 ),
}
}
Create a testactionCopy codeThe Code is as follows: Class testaction extends action {
Public Function Dtest (){
$ Test = D ('test'); // first case
$ Test = new model ('test'); // The second case
If ($ test-> Create ()){
$ Test-> Add ();
} Else {
$ Test-> geterror ();
}
}
}
When running, you will find that the data check function is available for a model instance in the first method, if the title is not entered, the system prompts "Enter the title" (this is an automatic verification feature provided by TP, and the verification criteria must be defined in the corresponding model ); if the second method is used, there will be no ·····