当前位置: 首页>>代码示例>>PHP>>正文


PHP CModel::defineIndexes方法代码示例

本文整理汇总了PHP中CModel::defineIndexes方法的典型用法代码示例。如果您正苦于以下问题:PHP CModel::defineIndexes方法的具体用法?PHP CModel::defineIndexes怎么用?PHP CModel::defineIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CModel的用法示例。


在下文中一共展示了CModel::defineIndexes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getRules


//.........这里部分代码省略.........
                 $uniqueAttributes[] = $name;
             }
         }
         // Required
         if ($config['type'] != AttributeType::Bool && !empty($config['required'])) {
             $requiredAttributes[] = $name;
         }
         // Lengths
         if ($config['type'] != AttributeType::Number && $config['type'] != AttributeType::Mixed) {
             if (isset($config['length']) && is_numeric($config['length'])) {
                 $strictLengthAttributes[(string) $config['length']][] = $name;
             } else {
                 // Only worry about min- and max-lengths if a strict length isn't set
                 if (isset($config['minLength']) && is_numeric($config['minLength'])) {
                     $minLengthAttributes[(string) $config['minLength']][] = $name;
                 }
                 if (isset($config['maxLength']) && is_numeric($config['maxLength'])) {
                     $maxLengthAttributes[(string) $config['maxLength']][] = $name;
                 }
             }
         }
         // Compare with other attributes
         if (isset($config['compare'])) {
             $comparisons = ArrayHelper::stringToArray($config['compare']);
             foreach ($comparisons as $comparison) {
                 if (preg_match('/^(==|=|!=|>=|>|<=|<)\\s*\\b(.*)$/', $comparison, $match)) {
                     $rules[] = array($name, 'compare', 'compareAttribute' => $match[2], 'operator' => $match[1], 'allowEmpty' => true);
                 }
             }
         }
         // Regex pattern matching
         if (!empty($config['matchPattern'])) {
             $rules[] = array($name, 'match', 'pattern' => $config['matchPattern']);
         }
     }
     // If this is a BaseRecord instance, catch any unique/required indexes. We don't validate required BELONGS_TO
     // relations because they might not get set until after validation.
     if ($model instanceof BaseRecord) {
         foreach ($model->defineIndexes() as $config) {
             $unique = !empty($config['unique']);
             $required = !empty($config['required']);
             if ($unique || $required) {
                 $columns = ArrayHelper::stringToArray($config['columns']);
                 if ($unique) {
                     if (count($columns) == 1) {
                         if (empty($attributes[$columns[0]]['required']) && (isset($attributes[$columns[0]]['null']) && $attributes[$columns[0]]['null'] === false)) {
                             $uniqueRequiredAttributes[] = $columns[0];
                         } else {
                             $uniqueAttributes[] = $columns[0];
                         }
                     } else {
                         $initialColumn = array_shift($columns);
                         $rules[] = array($initialColumn, 'Craft\\CompositeUniqueValidator', 'with' => implode(',', $columns));
                     }
                 }
                 if ($required) {
                     $requiredAttributes = array_merge($requiredAttributes, $columns);
                 }
             }
         }
     }
     if ($uniqueAttributes) {
         $rules[] = array(implode(',', $uniqueAttributes), 'unique');
     }
     if ($uniqueRequiredAttributes) {
         $rules[] = array(implode(',', $uniqueRequiredAttributes), 'unique', 'allowEmpty' => false);
     }
     if ($requiredAttributes) {
         $rules[] = array(implode(',', $requiredAttributes), 'required');
     }
     if ($emailAttributes) {
         $rules[] = array(implode(',', $emailAttributes), 'email');
     }
     if ($urlAttributes) {
         $rules[] = array(implode(',', $urlAttributes), 'Craft\\UrlValidator', 'defaultScheme' => 'http');
     }
     if ($urlFormatAttributes) {
         $rules[] = array(implode(',', $urlFormatAttributes), 'Craft\\UrlFormatValidator');
     }
     if ($uriAttributes) {
         $rules[] = array(implode(',', $uriAttributes), 'Craft\\UriValidator');
     }
     if ($strictLengthAttributes) {
         foreach ($strictLengthAttributes as $strictLength => $attributeNames) {
             $rules[] = array(implode(',', $attributeNames), 'length', 'is' => (int) $strictLength);
         }
     }
     if ($minLengthAttributes) {
         foreach ($minLengthAttributes as $minLength => $attributeNames) {
             $rules[] = array(implode(',', $attributeNames), 'length', 'min' => (int) $minLength);
         }
     }
     if ($maxLengthAttributes) {
         foreach ($maxLengthAttributes as $maxLength => $attributeNames) {
             $rules[] = array(implode(',', $attributeNames), 'length', 'max' => (int) $maxLength);
         }
     }
     $rules[] = array(implode(',', array_keys($attributes)), 'safe', 'on' => 'search');
     return $rules;
 }
开发者ID:webremote,项目名称:Craft-Release,代码行数:101,代码来源:ModelHelper.php


注:本文中的CModel::defineIndexes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。