The difference of example model method in thinkphp _php skill

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.