In TP, we can use the following two ways to create a data table mapping object (I used temporarily)
First type: $Test = D (' Test ')
Second type: $Test = new Model (' Test ')
Although both of these can be select,insert,delete,udpate operations on data, there is a big difference in data validation,
Let's take a look at the effect and first create a Testmodel
Copy the Code code as follows:
Class Testmodel extends model{
protected $_validate = array{
Array (' title ', ' Require ', ' Please enter title ', 1),
Array (' content ', ' require ', ' please input ', 1),
}
}
Create a Testaction
Copy the Code code 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 ();
}
}
}
In the run, you will find that the first way to instance a model will have a data check function, if the title is not filled out, you will be prompted "Please enter the title" (This is a TP provides an automatic verification function, of course, you need to define the appropriate model in the validation conditions) ; If you use the second one, there's no.
The above describes the ThinkPad E40 0578a64 thinkphp Example of the difference between the model method, including the ThinkPad E40 0578a64 aspects, I hope to be interested in PHP tutorial friends helpful.