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


PHP DynamicModel::init方法代码示例

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


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

示例1: init

 public function init()
 {
     parent::init();
     // Build definitions.
     if (!empty($this->ctype)) {
         $filePath = \Yii::getAlias('@app/workspace/elements') . DIRECTORY_SEPARATOR . $this->ctype . '.json';
         $elementDefinition = Json::decode(file_get_contents($filePath), false);
         // Add core fields.
         $elementDefinition->fields[] = Json::decode('{ "label": "UUID", "key": "uuid", "type": "textInput", "visibleInGrid": true, "rules": [["string", {"max": 128}]], "options": {"disabled":true}}', false);
         $elementDefinition->fields[] = Json::decode('{ "label": "Path", "key": "path", "type": "textInput", "visibleInGrid": true, "rules": [["string", {"max": 128}]]}', false);
         $elementDefinition->fields[] = Json::decode('{ "label": "Slug", "key": "slug", "type": "textInput", "visibleInGrid": true, "rules": [["string", {"max": 128}]]}', false);
         $elementDefinition->fields[] = Json::decode('{ "label": "State", "key": "state", "type": "dropDownList", "visibleInGrid": true, "rules": [["required"], ["integer"]], "options": {"prompt":"Please set state"}, "items": {"0":"Offline", "1":"Draft", "2":"Online", "3":"Archived"}}', false);
         $elementDefinition->fields[] = Json::decode('{ "label": "Created", "key": "created", "type": "textInput", "visibleInGrid": true, "rules": [["string", {"max": 128}]]}', false);
         $elementDefinition->fields[] = Json::decode('{ "label": "Updated", "key": "updated", "type": "textInput", "visibleInGrid": true, "rules": [["string", {"max": 128}]]}', false);
         $elementDefinition->fields[] = Json::decode('{ "label": "Publish from", "key": "from", "type": "textInput", "visibleInGrid": true, "rules": [["string", {"max": 128}]]}', false);
         $elementDefinition->fields[] = Json::decode('{ "label": "Publish to", "key": "to", "type": "textInput", "visibleInGrid": true, "rules": [["string", {"max": 128}]]}', false);
         $this->fieldDefinitions = $elementDefinition;
         $fields = [];
         // Build field array.
         foreach ($elementDefinition->fields as $field) {
             array_push($fields, $field->key);
         }
         $this->identifier = $this->ctype;
         // Populate attributes.
         foreach ($fields as $name => $value) {
             if (is_int($name)) {
                 $this->defineAttribute($value, null);
             } else {
                 $this->defineAttribute($name, $value);
             }
         }
         // Add validation rules.
         foreach ($elementDefinition->fields as $field) {
             $this->defineLabel($field->key, $field->label);
             if (!empty($field->rules)) {
                 foreach ($field->rules as $rule) {
                     if (empty($rule[1])) {
                         $this->addRule([$field->key], $rule[0]);
                     } else {
                         $this->addRule([$field->key], $rule[0], (array) $rule[1]);
                     }
                 }
             }
         }
         // Load model from file.
         if (!empty($this->uuid)) {
             $data['CrelishDynamicJsonModel'] = Json::decode(file_get_contents(\Yii::getAlias('@app/workspace/data/') . DIRECTORY_SEPARATOR . $this->ctype . DIRECTORY_SEPARATOR . $this->uuid . '.json'));
             $this->load($data);
         }
     }
 }
开发者ID:giantbits,项目名称:yii2-crelish,代码行数:51,代码来源:CrelishDynamicJsonModel.php

示例2: init

 public function init()
 {
     parent::init();
     if ($this->relatedElementModel->relatedProperties) {
         foreach ($this->relatedElementModel->relatedProperties as $property) {
             $this->defineAttribute($property->code, $property->handler->isMultiple ? [] : null);
             $property->relatedPropertiesModel = $this;
             $property->addRules();
             $this->_properties[$property->code] = $property;
         }
     }
     if ($relatedElementProperties = $this->relatedElementModel->relatedElementProperties) {
         foreach ($this->_properties as $code => $property) {
             if ($property->handler->isMultiple) {
                 $values = [];
                 $valuesModels = [];
                 foreach ($relatedElementProperties as $propertyElementVal) {
                     if ($propertyElementVal->property_id == $property->id) {
                         $values[$propertyElementVal->id] = $propertyElementVal->value;
                         $valuesModels[$propertyElementVal->id] = $propertyElementVal;
                     }
                 }
                 $values = $property->handler->initValue($values);
                 $this->setAttribute($code, $values);
                 $this->_propertyValues[$code] = $valuesModels;
             } else {
                 $value = null;
                 $valueModel = null;
                 foreach ($relatedElementProperties as $propertyElementVal) {
                     if ($propertyElementVal->property_id == $property->id) {
                         $value = $propertyElementVal->value;
                         $valueModel = $propertyElementVal;
                         break;
                     }
                 }
                 $value = $property->handler->initValue($value);
                 $this->setAttribute($code, $value);
                 $this->_propertyValues[$code] = $valueModel;
             }
         }
     }
 }
开发者ID:skeeks-cms,项目名称:cms,代码行数:42,代码来源:RelatedPropertiesModel.php

示例3: init

 public function init()
 {
     parent::init();
     $this->_owner = Instance::ensure($this->_owner, Params::className());
 }
开发者ID:zarv1k,项目名称:yii2-params,代码行数:5,代码来源:DynamicParam.php


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