ThinkPad E40 0578a64 thinkphp Example of the model method of the difference description

Source: Internet
Author: User
In TP, we can use the following two ways to create a data table mapping object (I used temporarily)
First type: $Test = D (' Test ')
Second type: $Test = new Model (' Test ')
Although both of these can be select,insert,delete,udpate operations on data, there is a big difference in data validation,
Let's take a look at the effect and first create a Testmodel

Copy the Code code as follows:


Class Testmodel extends model{
protected $_validate = array{
Array (' title ', ' Require ', ' Please enter title ', 1),
Array (' content ', ' require ', ' please input ', 1),
}
}


Create a Testaction

Copy the Code code as follows:


Class Testaction extends action{
Public Function dtest () {
$test = D (' test '); First case
$test = new Model (' Test '); The second case
if ($test->create ()) {
$test->add ();
}else{
$test->geterror ();
}
}
}


In the run, you will find that the first way to instance a model will have a data check function, if the title is not filled out, you will be prompted "Please enter the title" (This is a TP provides an automatic verification function, of course, you need to define the appropriate model in the validation conditions) ; If you use the second one, there's no.

The above describes the ThinkPad E40 0578a64 thinkphp Example of the difference between the model method, including the ThinkPad E40 0578a64 aspects, I hope to be interested in PHP tutorial friends helpful.

  • 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.