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


PHP ActiveRecord::setAttribute方法代码示例

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


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

示例1: saveFile

 /**
  * @return bool
  * @throws \yii\base\Exception
  */
 protected function saveFile()
 {
     if ($this->uploadFile && $this->uploadFile instanceof UploadedFile) {
         if (!file_exists($this->uploadDir)) {
             FileHelper::createDirectory($this->uploadDir, '0777');
         }
         if ($this->uploadFile->saveAs($this->getFilePath($this->getFileName()))) {
             $this->owner->setAttribute($this->attribute, $this->getFileName());
             return true;
         }
     } else {
         $this->owner->setAttribute($this->attribute, $this->owner->getOldAttribute($this->attribute));
     }
     return false;
 }
开发者ID:yiidoc,项目名称:yii2-upload-behavior,代码行数:19,代码来源:UploadFileBehavior.php

示例2: afterFind

 /**
  * Handle 'afterFind' event of the owner.
  */
 public function afterFind()
 {
     if ($this->owner->isRelationPopulated('translations') && ($related = $this->owner->getRelatedRecords()['translations'])) {
         $translations = $this->indexByLanguage($related);
         foreach ($this->availableLanguages as $lang) {
             foreach ($this->attributes as $attribute) {
                 foreach ($translations as $translation) {
                     if ($translation->{$this->languageField} == $lang) {
                         $this->setTranslateAttribute($attribute . '_' . $lang, $translation->{$attribute});
                         if ($lang == Yii::$app->language) {
                             $this->setTranslateAttribute($attribute, $translation->{$attribute});
                         }
                     }
                 }
             }
         }
     } else {
         if (!$this->owner->isRelationPopulated('translation')) {
             $this->owner->translation;
         }
         $translation = $this->owner->getRelatedRecords()['translation'];
         if ($translation) {
             foreach ($this->attributes as $attribute) {
                 $this->owner->setTranslateAttribute($attribute, $translation->{$attribute});
             }
         }
     }
     foreach ($this->attributes as $attribute) {
         if ($this->owner->hasAttribute($attribute) && $this->getTranslateAttribute($attribute)) {
             $this->owner->setAttribute($attribute, $this->getTranslateAttribute($attribute));
         }
     }
 }
开发者ID:navatech,项目名称:yii2-multi-language,代码行数:36,代码来源:LanguageBehavior.php

示例3: setAttribute

 /**
  * @inheritdoc
  */
 public function setAttribute($name, $value)
 {
     if ($this->tryToSetRelation($name, $value)) {
         return;
     }
     parent::setAttribute($name, $value);
 }
开发者ID:yinheark,项目名称:yincart2,代码行数:10,代码来源:ActiveRecord.php

示例4: setAttribute

 public function setAttribute($name, $value)
 {
     if (isset($this->{$name})) {
         $this->{$name} = $value;
     } else {
         parent::setAttribute($name, $value);
     }
 }
开发者ID:noikiy,项目名称:wowewe,代码行数:8,代码来源:MWxAction.php

示例5: loadModel

 /**
  * Populate model data
  * @param ActiveRecord $model the model to populate
  * @param array $modelData
  * @return bool true if success
  */
 public function loadModel($model, $modelData)
 {
     $model->trigger('beforeLoad');
     if (empty($modelData)) {
         return false;
     }
     $attributes = $model->attributes();
     $b = false;
     foreach ($attributes as $attrName) {
         if (array_key_exists($attrName, $modelData)) {
             $model->setAttribute($attrName, $modelData[$attrName]);
             $b = true;
         }
     }
     $model->trigger('afterLoad');
     return $b;
 }
开发者ID:fproject,项目名称:yii2-restx,代码行数:23,代码来源:SaveActionTrait.php

示例6: performTransition

 /**
  * Perform last checks and the actual state transition.
  *
  * @param \yii\db\ActiveRecord|IStateful $model
  * @param array                          $stateChange
  * @param mixed                          $sourceState
  * @param boolean                        $confirmed
  *
  * @return bool true if state transition has been performed
  */
 public function performTransition($model, $stateChange, $sourceState, $confirmed = true)
 {
     // explicitly assign the new state value to avoid forcing the state attribute to be safe
     $model->setAttribute($model->getStateAttributeName(), $this->targetState);
     if (!$this->beforeTransition($model) || $model->performTransition() === false) {
         return false;
     }
     $this->afterTransition($model);
     return true;
 }
开发者ID:netis-pl,项目名称:yii2-fsm,代码行数:20,代码来源:StateActionTrait.php

示例7: beforeUpdate

 /**
  * Метод срабатывает в момент обновления существующей записи моедли.
  */
 public function beforeUpdate()
 {
     if (in_array($this->owner->scenario, $this->scenarios)) {
         foreach ($this->attributes as $attribute) {
             if ($this->owner->isAttributeChanged($attribute)) {
                 $fileTempPath = $this->getTempPath($attribute);
                 if (is_file($fileTempPath)) {
                     rename($fileTempPath, $this->getPath($attribute));
                     if ($this->deleteOnSave === true and $this->owner->getOldAttribute($attribute)) {
                         $this->delete($attribute, true);
                     }
                     $this->triggerEventAfterUpload();
                 } else {
                     $this->owner->setAttribute($attribute, $this->owner->getOldAttribute($attribute));
                 }
             }
         }
     }
     // Удаляем указаные атрибуты и их файлы если это нужно
     if (!empty($this->deleteScenarios) and in_array($this->owner->scenario, $this->deleteScenarios)) {
         foreach ($this->deleteScenarios as $attribute => $scenario) {
             if ($this->owner->scenario === $scenario) {
                 $file = $this->getPath($attribute);
                 if (is_file($file) and unlink($file)) {
                     $this->owner->{$attribute} = null;
                 }
             }
         }
     }
 }
开发者ID:lembadm,项目名称:yii2-fileapi-behavior,代码行数:33,代码来源:UploadBehavior.php

示例8: setAttribute

 public function setAttribute($name, $value)
 {
     if ($this->trySetupEmbeddedRelation($name, $value)) {
         // if success
         return;
     }
     parent::setAttribute($name, $value);
 }
开发者ID:haiflive,项目名称:orientdb-yii2-connector,代码行数:8,代码来源:ActiveRecord.php

示例9: setSort

 public function setSort($position)
 {
     $this->owner->setAttribute($this->attributeName, $position);
 }
开发者ID:nanodesu88,项目名称:yii2-activerecord-sort,代码行数:4,代码来源:SortBehavior.php

示例10: setAttribute

 /**
  * Sets the named attribute value.
  * @param string $name
  *        the attribute name
  * @param mixed $value
  *        the attribute value.
  * @throws InvalidParamException if the named attribute does not exist.
  * @throws Exception if the current record is read only
  * @see hasAttribute()
  */
 public function setAttribute($name, $value)
 {
     if ($this->getReadOnly()) {
         throw new Exception('Attempting to set attribute `' . $name . '` on a read only ' . Tools::getClassName($this) . ' model');
     }
     parent::setAttribute($name, $value);
 }
开发者ID:fangface,项目名称:yii2-concord,代码行数:17,代码来源:ActiveRecord.php


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