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


PHP Model::rules方法代码示例

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


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

示例1: rules

 public function rules()
 {
     $result = parent::rules();
     foreach ($this->relatedElementModel->relatedProperties as $proeperty) {
         $result = ArrayHelper::merge($result, $proeperty->rulesForActiveForm());
     }
     return $result;
 }
开发者ID:Liv1020,项目名称:cms,代码行数:8,代码来源:RelatedPropertiesModel.php

示例2: testDefaults

 public function testDefaults()
 {
     $singer = new Model();
     $this->assertEquals([], $singer->rules());
     $this->assertEquals([], $singer->attributeLabels());
 }
开发者ID:rajanishtimes,项目名称:basicyii,代码行数:6,代码来源:ModelTest.php

示例3: buildParameters

 public function buildParameters()
 {
     $rules = $this->originalModel->rules();
     foreach ($rules as $rule) {
         if (isset($rule['on']) && $rule['on'] !== $this->scenario) {
             continue;
         }
         if (is_array($rule[0])) {
             foreach ($rule[0] as $name) {
                 if (!isset($this->parameters[$name])) {
                     $this->parameters[$name] = [];
                 }
                 if ($rule[1] === 'required') {
                     $this->parameters[$name]['required'] = true;
                 }
                 if (in_array($rule[1], ['string', 'number', 'integer', 'boolean'])) {
                     $this->parameters[$name]['type'] = $rule[1];
                 }
                 if ($rule[1] === 'each') {
                     $this->parameters[$name]['type'] = Swagger::DATA_TYPE_ARRAY;
                     $this->parameters[$name]['items']['type'] = Swagger::DATA_TYPE_STRING;
                 }
             }
         } elseif (is_string($rule[0])) {
             $name = $rule[0];
             if (!isset($this->parameters[$name])) {
                 $this->parameters[$name] = [];
             }
             if ($rule[1] === 'required') {
                 $this->parameters[$name]['required'] = true;
             }
             if (in_array($rule[1], ['string', 'number', 'integer', 'boolean'])) {
                 $this->parameters[$name]['type'] = $rule[1];
             }
             if ($rule[1] === 'each') {
                 $this->parameters[$name]['type'] = Swagger::DATA_TYPE_ARRAY;
                 $this->parameters[$name]['items']['type'] = Swagger::DATA_TYPE_STRING;
             }
         }
     }
     foreach ($this->parameters as $name => $items) {
         $this->parameters[$name]['description'] = $this->modelAnnotationParser->getPropertyDesc($name) ?: var2HumanReadable($name);
         $this->parameters[$name]['required'] = isset($this->parameters[$name]['required']) ? $this->parameters[$name]['required'] : false;
         if (!isset($this->parameters[$name]['type'])) {
             if ($this->annotationParser->getPropertyType($name) === Swagger::DATA_TYPE_OBJECT) {
                 if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($name))) {
                     $subFormModel = new FormModel(new $objectClass(), REST::SCENARIO_DEFAULT);
                     $this->subFormModels[] = $subFormModel;
                     $this->parameters[$name]['$ref'] = "#/definitions/{$subFormModel->name}";
                 } else {
                     $this->parameters[$name]['type'] = Swagger::DATA_TYPE_OBJECT;
                 }
             } elseif ($this->annotationParser->getPropertyType($name) === Swagger::DATA_TYPE_OBJECT_ARRAY) {
                 $this->parameters[$name]['type'] = Swagger::DATA_TYPE_ARRAY;
                 if (!is_null($objectClass = $this->annotationParser->getPropertyObjectClass($name))) {
                     $subFormModel = new FormModel(new $objectClass(), REST::SCENARIO_DEFAULT);
                     $this->subFormModels[] = $subFormModel;
                     $this->parameters[$name]['items']['$ref'] = "#/definitions/{$subFormModel->name}";
                 } else {
                     $this->parameters[$name]['items']['type'] = Swagger::DATA_TYPE_STRING;
                 }
             } else {
                 $this->parameters[$name]['type'] = Swagger::DATA_TYPE_STRING;
             }
         }
     }
 }
开发者ID:jiangrongyong,项目名称:docgen,代码行数:67,代码来源:FormModel.php

示例4: rules

 public function rules()
 {
     return array_merge(parent::rules(), [[['oldpassword', 'newpassword'], 'required'], ['newpassword', 'string', 'min' => 6, 'max' => 16], ['oldpassword', 'checkPassword']]);
 }
开发者ID:dawei101,项目名称:plants,代码行数:4,代码来源:ChangePasswordForm.php


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