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