當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ActiveRecord::setAttributes方法代碼示例

本文整理匯總了PHP中yii\db\ActiveRecord::setAttributes方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveRecord::setAttributes方法的具體用法?PHP ActiveRecord::setAttributes怎麽用?PHP ActiveRecord::setAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\db\ActiveRecord的用法示例。


在下文中一共展示了ActiveRecord::setAttributes方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->modelClass) {
         throw new InvalidArgumentException('Param "modelClass" must be non-empty');
     }
     if (!is_subclass_of($this->modelClass, 'voskobovich\\base\\interfaces\\ModelInterface')) {
         throw new InvalidArgumentException('Param "modelClass" must be extend "voskobovich\\base\\interfaces\\ModelInterface"');
     }
     $this->_model = Yii::createObject($this->modelClass);
     $this->_model->setAttributes($this->initAttributes);
     parent::init();
 }
開發者ID:voskobovich,項目名稱:yii2-base-toolkit,代碼行數:15,代碼來源:FormWrapper.php

示例2: setAttributes

 /**
  * rewrite set attributes, set relation data to relations, auto save at after save
  * @inheritdoc
  */
 public function setAttributes($values, $safeOnly = true)
 {
     if (is_array($values)) {
         foreach ($values as $name => $value) {
             $this->tryToSetRelation($name, $value);
         }
     }
     parent::setAttributes($values, $safeOnly);
 }
開發者ID:yinheark,項目名稱:yincart2,代碼行數:13,代碼來源:ActiveRecord.php

示例3: setAttributes

 public function setAttributes($values, $safeOnly = true)
 {
     if (is_array($values)) {
         foreach ($values as $key => $value) {
             if (is_array($value)) {
                 unset($values[$key]);
             }
         }
     }
     parent::setAttributes($values, $safeOnly);
 }
開發者ID:noikiy,項目名稱:wowewe,代碼行數:11,代碼來源:MAccessLogAll.php

示例4: setAttributes

 /**
  * Extends setAttributes to handle active date fields
  *
  * @param $values array
  * @param $safeOnly boolean
  */
 public function setAttributes($values, $safeOnly = true)
 {
     foreach ($this->widgetAttributes() as $fieldName => $className) {
         $className = '\\marsoltys\\yii2user\\components\\' . $className;
         if (isset($values[$fieldName]) && class_exists($className)) {
             $class = new $className();
             $arr = $this->widgetParams($fieldName);
             if ($arr) {
                 $newParams = $class->params;
                 $arr = (array) Json::decode($arr);
                 foreach ($arr as $p => $v) {
                     if (isset($newParams[$p])) {
                         $newParams[$p] = $v;
                     }
                 }
                 $class->params = $newParams;
             }
             if (method_exists($class, 'setAttributes')) {
                 $values[$fieldName] = $class->setAttributes($values[$fieldName], $this, $fieldName);
             }
         }
     }
     parent::setAttributes($values, $safeOnly);
 }
開發者ID:marsoltys,項目名稱:yii2user,代碼行數:30,代碼來源:UActiveRecord.php

示例5: setAttributes

 public function setAttributes($attributes)
 {
     $model = $this->getModel();
     foreach ($attributes as $attribute => $value) {
         if (in_array($attribute, $this->pageAttributes)) {
             $model->title = $value;
             unset($attributes[$attribute]);
             continue;
         }
     }
     $model->save();
     $attributes['pageId'] = $model->id;
     parent::setAttributes($attributes);
 }
開發者ID:nurastana,項目名稱:familyclinickz,代碼行數:14,代碼來源:Model.php

示例6: setAttributes

 /**
  * Check if some attributes uploaded via fileInput field
  * and assign them with UploadedFile
  *
  * @inheritdoc
  */
 public function setAttributes($values, $safeOnly = true)
 {
     parent::setAttributes($values, $safeOnly);
     // Looking only for file attributes (and fix null error on fly)
     if (is_array($values)) {
         $attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes());
         $class = StringHelper::basename(get_called_class());
         foreach ($values as $name => $value) {
             if (isset($attributes[$name])) {
                 if (isset($_FILES[$class]['name'][$name])) {
                     $uploadedFile = UploadedFile::getInstance($this, $name);
                     if ($uploadedFile) {
                         $this->{$name} = $uploadedFile;
                     } elseif (!$this->isNewRecord) {
                         $this->{$name} = $this->oldAttributes[$name];
                     }
                 }
             }
         }
     }
 }
開發者ID:webvimark,項目名稱:components,代碼行數:27,代碼來源:BaseActiveRecord.php

示例7: _setValue

 /**
  * @inheritDoc
  */
 protected function _setValue(ActiveRecord $model, $value)
 {
     /** @var ActiveRecord $model */
     $model->setAttributes([$this->attributeName => $value]);
     return true;
 }
開發者ID:nanodesu88,項目名稱:easyii,代碼行數:9,代碼來源:ActiveDataColumn.php

示例8: setAttributes

 /**
  * (non-PHPdoc)
  * @see \yii\base\Model::setAttributes()
  * @throws Exception if the current record is read only
  */
 public function setAttributes($values, $safeOnly = true)
 {
     if ($this->getReadOnly()) {
         throw new Exception('Attempting to set attributes on a read only ' . Tools::getClassName($this) . ' model');
     }
     parent::setAttributes($values, $safeOnly);
 }
開發者ID:fangface,項目名稱:yii2-concord,代碼行數:12,代碼來源:ActiveRecord.php


注:本文中的yii\db\ActiveRecord::setAttributes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。