Home > Backend Development > PHP Tutorial > thinkpad e40 0578a64 Explanation of the differences between instance Model methods in ThinkPHP

thinkpad e40 0578a64 Explanation of the differences between instance Model methods in ThinkPHP

WBOY
Release: 2016-07-29 08:43:40
Original
1463 people have browsed it

In TP, we can use the following two methods to create a mapping object of a data table (the one 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 content',1),
}
}


Create a TestAction

Copy code The 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 if you use the first method to instantiate a model, there will be data checking 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, the verification conditions need to be defined in the corresponding model); if you use the second type, there will be no... ···

The above introduces the differences between the instance Model methods in thinkpad e40 0578a64 ThinkPHP, including the content of thinkpad e40 0578a64. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template