Where can I perform data verification before calling the model?

Source: Internet
Author: User
To exclude form verification, for example, if you want to call a Model method in the controller, transfer it to one of the parameters in this method, for example, $ city_id is actually the $ city_id, that is, it can be an int or an array. So where are the $ city_id POST at this time... Exclude Form Verification

For exampleModel, Then pass to one of the parameters in this method, such$city_idActually, this$city_idThat is, it can beintIt can also bearray

In this case, POST$city_idGenerally, the verification is conducted.

  1. If the model verification is performed, it is difficult to tune the model once more.

  2. However, if the model is verified by the Controller, I think it is better to validate the model once, in case other people call my own method and directly query the data without checking the controller. In this case, the controller and the model perform the same verification on the data twice.

So I would like to ask you how to deal with the most common encoding process?

Reply content:

Exclude Form Verification

For exampleModel, Then pass to one of the parameters in this method, such$city_idActually, this$city_idThat is, it can beintIt can also bearray

In this case, POST$city_idGenerally, the verification is conducted.

  1. If the model verification is performed, it is difficult to tune the model once more.

  2. However, if the model is verified by the Controller, I think it is better to validate the model once, in case other people call my own method and directly query the data without checking the controller. In this case, the controller and the model perform the same verification on the data twice.

So I would like to ask you how to deal with the most common encoding process?

I usually filter the read/write information of the database. As follows:

User_modelpublic function get_user_name ($ uid) {$ uid = intval ($ uid); // check if (! $ Uid) {return FALSE;} esle {.... // database query operation} controllerpublic function user () {$ uid = $ _ GET ['id]; if (! M ('user _ model')-> get_user_name ($ uid) {return FALSE;} // subsequent operations}

If there is a built-in filtering method for the Framework, the pdo mechanism is also quite high;

Check all data. Haha, It is required before database operations ~

If you think about it, it is more reasonable to filter the model.

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.