Questions about where to put the thinkphp data validation

Source: Internet
Author: User
I am a novice, in the practice of the code encountered a problem is that in the long form to submit data validation, I should put the validation on the controller layer or should be placed in the model layer, this validation includes the judge whether the field is empty, but also to determine the uniqueness of a field and so on. I checked the next, some of the answer is to verify on the controller layer, but TP manual has an automatic verification, this is placed on the model layer, so a little confused forced, I hope that the great God to point.

Reply content:

I am a novice, in the practice of the code encountered a problem is that in the long form to submit data validation, I should put the validation on the controller layer or should be placed in the model layer, this validation includes the judge whether the field is empty, but also to determine the uniqueness of a field and so on. I checked the next, some of the answer is to verify on the controller layer, but TP manual has an automatic verification, this is placed on the model layer, so a little confused forced, I hope that the great God to point.

Give you a manual link, hoping to help you to automatically verify

You can test the data according to the validate defined in model before automatically creating the data $this->create () on the model layer. Personally, encapsulation is better. This is called dynamic validate.

The project I am writing is in the controller.

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