In TP, we can use the following two ways to create a data table mapping object (I temporarily use)
First: $Test = D (' Test ')
Second: $Test = new Model (' Test ')
Although both types of data can be select,insert,delete,udpate operations, there is a great difference in data validation,
Let's look at the effect, first create a Testmodel
Copy Code code as follows:
Class Testmodel extends model{
protected $_validate = array{
Array (' title ', ' Require ', ' Please enter title ', 1),
Array (' content ', ' require ', ' Please enter content ', 1),
}
}
Create a Testaction
Copy Code code as follows:
Class Testaction extends action{
Public Function dtest () {
$test = D (' test '); The first case
$test = new Model (' Test '); Second case
if ($test->create ()) {
$test->add ();
}else{
$test->geterror ();
}
}
}
At the time of running, you will find that the first example of a model will have data checking function, if the title did not fill out the words will prompt "Please enter the title" (This is TP provide an automatic verification function, of course, also need to be in the corresponding model to define a good validation conditions) ; If you use the second kind, there's no.