In TP, we can use the following two methods to create a map object for a data table (I used temporarily)
The first type: $Test = D('Test')
The second type: $Test = new Model('Test')
Although both of these can perform select, insert, delete, and udpate operations on the data, there are great differences in data verification.
Let's take a look at the effect and first create a TestModel
class TestModel extends Model{
protected $_validate = array{
array('title','require','Please enter the title',1),
array('content','require','please enter content',1),
}
}
Create a TestAction
class TestAction extends Action{
public function Dtest(){
$test = D('Test'); //The first case
$test = new Model('Test'); //The second case
if($test->Create()){
$test->Add();
}else{
$test->getError();
}
}
}
When running, you will find that using the first method to test a model, it will have a data check function. If the title is not filled in, it will prompt "Please enter the title" (this is an automatic verification function provided by TP. Of course, it also needs to define the verification conditions in the corresponding model); if the second method is used, it will be gone...
The first type: $Test = D('Test')
The second type: $Test = new Model('Test')
Although both of these can perform select, insert, delete, and udpate operations on the data, there are great differences in data verification.
Let's take a look at the effect and first create a TestModel
Copy the codeThe code is as follows:
class TestModel extends Model{
protected $_validate = array{
array('title','require','Please enter the title',1),
array('content','require','please enter content',1),
}
}
Create a TestAction
Copy the codeThe code is as follows:
class TestAction extends Action{
public function Dtest(){
$test = D('Test'); //The first case
$test = new Model('Test'); //The second case
if($test->Create()){
$test->Add();
}else{
$test->getError();
}
}
}
When running, you will find that using the first method to test a model, it will have a data check function. If the title is not filled in, it will prompt "Please enter the title" (this is an automatic verification function provided by TP. Of course, it also needs to define the verification conditions in the corresponding model); if the second method is used, it will be gone...