The safe usage of validator in Yii _php tutorial

Source: Internet
Author: User

The safe usage of validator in Yii


At the beginning of the use of Yii, has been the validation rules in the safe is not very understanding, today tested, is to understand the connotation of safe. Always think that safe is the framework of the input content filtering, such as SQL injection filter, in fact, is not, safe or unsafe is mainly in the $model->attributes=$_post[' User '; This assignment is called bulk copy (Massive Assignment) in Yii, and when all the properties in the model are safe, the value of the $_post[' User ' of the form submission can be assigned to $model->attributes. Then save into the database. However, once a property is not set to safe, such as username, when the user name is modified, you will find that the user name value is not updated, because username is unsafe, so massive The value of the new username cannot be assigned to the model in assignment.

Here is the explanation of the master:

Safe attributes refers to a property that is entered by the user and needs to be validated. If an attribute appears in a validation rule and the applicable scenario of the validation rule is the same as the model's current scenario, then the property is safe and can accept bulk assignment. In Yii 1.1, the Safeattributes () function has been canceled. All attributes are declared safe by a validation rule.

See also: http://www.yiiframework.com/wiki/161/understanding-safe-validation-rules/

Articles you may be interested in

    • The understanding of Yii Framework Yiiapp ()
    • How the YII framework configures the default controller and action
    • Summary of usage methods of database transactions in Yii
    • Analysis of module development of YII Framework Framework
    • YII rules common validation Rule memo
    • Methods for converting Yii object results to arrays
    • Yii database Add, modify, delete related Operations summary
    • The action parameter binding processing of YII controller

http://www.bkjia.com/PHPjc/1056390.html www.bkjia.com true http://www.bkjia.com/PHPjc/1056390.html techarticle The safe usage of validator in Yii at the beginning of the use of Yii, has been the validation of safe in the rule is not very understanding, today tested, is to understand the connotation of safe. Always thought sa ...

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