In TP, we can use the following two methods to create a mapping object of a data table (what I use temporarily)
The first method: $Test = D('Test')
The second method: $ Test = new Model('Test')
Although both can perform select, insert, delete, and udpate operations on data, they are very different in data verification.
Let’s take a look at the effect. First Create a TestModel
Copy code The code is as follows:
class TestModel extends Model{
protected $_validate = array{
array('title','require','Please enter the title',1),
array('content','require','Please enter the content',1),
}
}
Create a TestAction
Copy the code The code is as follows:
class TestAction extends Action{
public function Dtest(){
$test = D('Test'); //First case
$test = new Model('Test'); //Second case
if($test->Create()){
$test->Add();
}else{
$test->getError();
}
}
}
When running, you will find that using the first method to instantiate a model will have a data check function. If the title is not filled in, it will prompt "Please enter a title. ” (This is an automatic verification function provided by tp. Of course, the verification conditions need to be defined in the corresponding model); if you use the second method, it will not be available...
http://www.bkjia.com/PHPjc/322282.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322282.htmlTechArticleIn TP, we can use the following two methods to create a mapping object of a data table (I temporarily use ) The first one: $Test = D('Test') The second one: $Test = new Model('Test') Although this...