本文整理汇总了PHP中ProfileField::_rules方法的典型用法代码示例。如果您正苦于以下问题:PHP ProfileField::_rules方法的具体用法?PHP ProfileField::_rules怎么用?PHP ProfileField::_rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProfileField
的用法示例。
在下文中一共展示了ProfileField::_rules方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rules
/**
* Rules the input.
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
if (empty(self::$_rules) || self::$_refreshRules === true) {
self::$_rules = array();
self::$_refreshRules = false;
$fieldMetadata = $this->getAllFieldsMetadata();
/*
List of validators
* boolean * captcha * compare * date * default
* email * exist * file * filter * in
* length * numerical * match * required * safe
* type * unique * unsafe * url * lz_unique
*/
foreach ($fieldMetadata as $fieldName => $metadata) {
foreach ($metadata as $validator => $validatorAttributes) {
if ($validator !== 'not_validator') {
$temp = array($fieldName);
switch ($validator) {
// CBooleanValidator
case 'boolean':
/*
* Attributes:
* - allowEmpty: whether the attribute value can be null or empty (the default is true)
* - falseValue: the value representing the false status (0)
* - strict: whether the comparison to trueValue and falseValue is strict (false)
* - trueValue: the value representing the true status (1)
* Cassandra databases does not need these attributes.
*/
$temp[1] = 'boolean';
$temp['falseValue'] = false;
$temp['trueValue'] = true;
break;
// CCompareValidator
// CCompareValidator
case 'compare':
/*
* Attributes:
* - allowEmpty
* - compareAttribute: the name of the attribute to be compared with
* - compareValue: the constant value to be compared with
* - operator: the operator for comparison (==)
* - strict: whether the comparison is strict (both value and type must be the same) (false)
*/
$temp[1] = 'compare';
if (is_array($validatorAttributes)) {
if (isset($validatorAttributes['compareAttribute'])) {
$temp['compareAttribute'] = $validatorAttributes['compareAttribute'];
} elseif (isset($validatorAttributes['compareValue'])) {
$temp['compareValue'] = $validatorAttributes['compareValue'];
}
if (isset($validatorAttributes['operator'])) {
$temp['operator'] = $validatorAttributes['operator'];
}
if (isset($validatorAttributes['strict'])) {
$temp['strict'] = $validatorAttributes['strict'];
}
}
break;
// CDateValidator
// CDateValidator
case 'date':
/*
* Attributes:
* - allowEmpty
* - format: the format pattern that the date value should follow. This can be either a string or an array representing multiple formats. The formats are described in CDateTimeParser API ('MM/dd/yyyy')
* - timestampAttribute: name of the attribute that will receive date parsing result (null)
*/
$temp[1] = 'date';
if (is_array($validatorAttributes)) {
if (isset($validatorAttributes['format'])) {
$temp['format'] = $validatorAttributes['format'];
}
if (isset($validatorAttributes['timestampAttribute'])) {
$temp['timestampAttribute'] = $validatorAttributes['timestampAttribute'];
}
}
break;
// CDefaultValueValidator
// CDefaultValueValidator
case 'default':
/*
* Attributes:
* - setOnEmpty: whether to set the default value only when the attribute value is null or empty string (true)
* - value: the default value to be set to the specified attributes
*/
$temp[1] = 'default';
if (is_array($temp['default'])) {
if (isset($validatorAttributes['value'])) {
$temp['value'] = $validatorAttributes['value'];
}
if (isset($validatorAttributes['setOnEmpty'])) {
$temp['setOnEmpty'] = $validatorAttributes['setOnEmpty'];
}
}
//.........这里部分代码省略.........