當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。