Vasaris 2011

Programavimas

Yii framework validators

2011 m. vasario 25 d.

Sveiki, 

ištraukiau pagrindinius validatorius, kurie yra Yii frameworke:

Validation rules reference

  • boolean : CBooleanValidator, validates that the attribute value is either trueValue or falseValue.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. falseValue, the value representing false status.
    3. strict, whether the comparison to trueValue and falseValue is strict.
    4. trueValue, the value representing true status.
  • captcha : CCaptchaValidator, validates that the attribute value is the same as the verification code displayed in the CAPTCHA.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. captchaAction, ID of the action that renders the CAPTCHA image.
    3. caseSensitive, whether the comparison is case sensitive.
  • compare : CCompareValidator, compares the specified attribute value with another value and validates if they are equal.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. compareAttribute, the name of the attribute to be compared with.
    3. compareValue, the constant value to be compared with.
    4. operator, the operator for comparison.
    5. strict, whether the comparison is strict (both value and type must be the same.
  • default : CDefaultValueValidator, sets the attributes with the specified value. It does not do validation. Its existence is mainly to allow specifying attribute default values in a dynamic way.

    1. setOnEmpty, whether to set the default value only when the attribute value is null or empty string.
    2. value, the default value to be set to the specified attributes.
  • email : CEmailValidator, validates that the attribute value is a valid email address.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. allowName, whether to allow name in the email address.
    3. checkMX, whether to check the MX record for the email address.
    4. checkPort, whether to check port 25 for the email address.
    5. fullPattern, the regular expression used to validate email addresses with the name part.
    6. pattern, the regular expression used to validate the attribute value.
  • exist : CExistValidator, validates that the attribute value exists in a table.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. attributeName, the ActiveRecord class attribute name that should be used to look for the attribute value being validated.
    3. className, the ActiveRecord class name that should be used to look for the attribute value being validated.
    4. criteria, additional query criteria.
  • file : CFileValidator, verifies if an attribute is receiving a valid uploaded file.

    1. allowEmpty, whether the attribute requires a file to be uploaded or not.
    2. maxFiles, the maximum file count the given attribute can hold.
    3. maxSize, the maximum number of bytes required for the uploaded file.
    4. minSize, the minimum number of bytes required for the uploaded file.
    5. tooLarge, the error message used when the uploaded file is too large.
    6. tooMany, the error message used if the count of multiple uploads exceeds limit.
    7. tooSmall, the error message used when the uploaded file is too small.
    8. types, a list of file name extensions that are allowed to be uploaded.
    9. wrongType, the error message used when the uploaded file has an extension name that is not listed among extensions.
  • filter : CFilterValidator, transforms the data being validated based on a filter.

    1. filter, the filter method.
  • in : CRangeValidator, validates that the attribute value is among the list (specified via range).

    1. allowEmpty, whether the attribute value can be null or empty.
    2. range, list of valid values that the attribute value should be among.
    3. strict, whether the comparison is strict (both type and value must be the same).
  • length : CStringValidator, validates that the attribute value is of certain length.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. encoding , string encoding.
    3. is, exact length.
    4. max, maximum length.
    5. min, minimum length.
    6. tooLong, user-defined error message used when the value is too short.
    7. tooShort, user-defined error message used when the value is too long.
  • numerical : CNumberValidator, validates that the attribute value is a number.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. integerOnly, whether the attribute value can only be an integer.
    3. max, upper limit of the number.
    4. min, lower limit of the number.
    5. tooBig, user-defined error message used when the value is too big.
    6. tooSmall, user-defined error message used when the value is too small.
  • match : CRegularExpressionValidator, validates that the attribute value matches to the specified regular expression.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. pattern, the regular expression to be matched with.
  • required : CRequiredValidator, validates that the specified attribute does not have null or empty value.

    1. requiredValue, the desired value that the attribute must have.
    2. strict, whether the comparison to requiredValue is strict.
  • safe : CSafeValidator, marks the associated attributes to be safe for massive assignments.

  • type : CTypeValidator, verifies if the attribute is of the type specified by type. (integer, float, string, date, time, datetime)

    1. allowEmpty, whether the attribute value can be null or empty.
    2. dateFormat, the format pattern that the date value should follow.
    3. datetimeFormat, the format pattern that the datetime value should follow.
    4. timeFormat, the format pattern that the time value should follow.
    5. type, the data type that the attribute should be.

    Example of time rule;

    array('org_starttime, org_finishtime',  'type', 'type'=>'time', 'timeFormat'=>'hh:mm'),
  • unique : CUniqueValidator, validates that the attribute value is unique in the corresponding database table.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. attributeName, the ActiveRecord class attribute name that should be used to look for the attribute value being validated.
    3. caseSensitive, whether the comparison is case sensitive.
    4. className, the ActiveRecord class name that should be used to look for the attribute value being validated.
    5. criteria, additional query criteria.

    By default, CUniqueValidator works with a single attribute that's presumed to be unique across the whole model table, but it can work with multi-attribute unique constraints as well. See CUniqueValidator::c2215 for an example.

  • unsafe : CUnsafeValidator, marks the associated attributes to be unsafe so that they cannot be massively assigned.

  • url : CUrlValidator, validates that the attribute value is a valid http or https URL.

    1. allowEmpty, whether the attribute value can be null or empty.
    2. pattern, the regular expression used to validates the attribute value.

plačiau
Nuorodos

Dalinuosi nuoroda

2011 m. vasario 14 d.

http://code.google.com/more/table/

plačiau
Nuorodos

Kur galima skaityti dokumentus

2011 m. vasario 11 d.

http://www.docstoc.com/ 

http://www.scribd.com/ 


Kur dar?

plačiau