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


PHP CActiveRecord::setAttributes方法代码示例

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


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

示例1: setAttributes

 /**
  * rewrite set attributes, set relation data to relations, auto save at after save
  * @param array $values
  * @param bool $safeOnly
  * @author Lujie.Zhou(gao_lujie@live.cn, qq:821293064).
  */
 public function setAttributes($values, $safeOnly = true)
 {
     if (!is_array($values)) {
         return;
     }
     foreach ($values as $name => $value) {
         if (is_array($value) && isset($this->getMetaData()->relations[$name])) {
             $this->{$name} = $value;
         }
     }
     return parent::setAttributes($values, $safeOnly);
 }
开发者ID:lhfcainiao,项目名称:basic,代码行数:18,代码来源:YActiveRecord.php

示例2: getValidUserModel

 /**
  * Transfers collected values to the {@link HUserInfoForm::model}
  * 
  * @access public
  * @return void
  */
 public function getValidUserModel()
 {
     if ($this->hasErrors()) {
         return null;
     }
     // syncing only when we have a new model
     if ($this->_model->isNewRecord && strpos($this->scenario, '_pass') === false) {
         $this->_model->setAttributes(array($this->emailAtt => $this->email, $this->nameAtt => $this->username), false);
         if (HOAuthAction::$useYiiUser) {
             $this->_model->superuser = 0;
             $this->_model->status = Yii::app()->getModule('user')->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
             $this->_model->activkey = UserModule::encrypting(microtime() . $this->_model->email);
         }
     }
     return $this->model;
 }
开发者ID:EurekaSolutions,项目名称:proyectoestudio,代码行数:22,代码来源:HUserInfoForm.php

示例3: 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) {
				if (isset($values[$fieldName])&&class_exists($className)) {
					$class = new $className;
					$arr = $this->widgetParams($fieldName);
					if ($arr) {
						$newParams = $class->params;
						$arr = (array)CJavaScript::jsonDecode($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:rallin,项目名称:yii-user,代码行数:27,代码来源:UActiveRecord.php

示例4: setAttributes

 public function setAttributes($values, $safeOnly = false, $withRelation = true)
 {
     $cols = $this->tableSchema->columns;
     foreach ($values as $k => $v) {
         if (isset($cols[$k])) {
             if ($cols[$k]->dbType == 'datetime' || $cols[$k]->dbType == 'date' || $cols[$k]->dbType == 'time') {
                 if ($values[$k] == '') {
                     $values[$k] = null;
                 } else {
                     $values[$k] = $values[$k];
                 }
             }
         }
     }
     parent::setAttributes($values, $safeOnly);
     if ($withRelation) {
         $this->initRelation();
         foreach ($this->__relations as $k => $r) {
             if ($k != 'currentModel' && isset($values[$k])) {
                 $rel = $this->getMetaData()->relations[$k];
                 $this->__relations[$k] = $values[$k];
                 if (is_string($values[$k]) || is_array($values[$k])) {
                     if (is_string($values[$k])) {
                         $attr = json_decode($values[$k], true);
                         if (!is_array($attr)) {
                             $attr = [];
                         }
                     } else {
                         $attr = $values[$k];
                     }
                     if (Helper::is_assoc($values[$k])) {
                         switch (get_class($rel)) {
                             case 'CHasOneRelation':
                             case 'CBelongsToRelation':
                                 foreach ($attr as $i => $j) {
                                     if (is_array($j)) {
                                         unset($attr[$i]);
                                     }
                                 }
                                 $relArr = $this->{$k};
                                 if (is_object($relArr)) {
                                     $relArr->setAttributes($attr, false, false);
                                 }
                                 $this->__relations[$k] = $attr;
                                 break;
                         }
                     }
                 }
             }
             if (isset($values[$k . 'Insert'])) {
                 $value = $values[$k . 'Insert'];
                 $value = is_string($value) ? json_decode($value, true) : $value;
                 $this->__relInsert[$k] = $value;
             }
             if (isset($values[$k . 'Update'])) {
                 $value = $values[$k . 'Update'];
                 $value = is_string($value) ? json_decode($value, true) : $value;
                 $this->__relUpdate[$k] = $value;
             }
             if (isset($values[$k . 'Delete'])) {
                 $value = $values[$k . 'Delete'];
                 $value = is_string($value) ? json_decode($value, true) : $value;
                 $this->__relDelete[$k] = $value;
             }
             $this->applyRelChange($k);
         }
     }
     $ap = $this->getAttributeProperties();
     foreach ($ap as $k => $r) {
         if (isset($values[$k])) {
             $this->{$k} = $values[$k];
         }
     }
 }
开发者ID:rizabudi,项目名称:plansys,代码行数:74,代码来源:ActiveRecord.php

示例5: setAttributes

 public function setAttributes($values, $safeOnly = true)
 {
     if (isset($values['type']) && $this->type !== $values['type']) {
         $this->_typeChanged = true;
     }
     return parent::setAttributes($values, $safeOnly);
 }
开发者ID:shayanyi,项目名称:CRM,代码行数:7,代码来源:Fields.php

示例6: setAttributes

 public function setAttributes($values, $safeOnly = true)
 {
     return parent::setAttributes(DataHelper::arrayKeysCamelToSnake($values), $safeOnly);
 }
开发者ID:xexys,项目名称:xca-backend,代码行数:4,代码来源:ActiveRecord.php

示例7: setAttributes

 public function setAttributes($values, $safeOnly = true)
 {
     if (count($this->getFields()) > 0) {
         $test = __CLASS__ . ".setAttributes:\n";
         foreach ($values as $k => $v) {
             $test .= "[{$k}={$v}]\n";
         }
         $test .= "\nparse field values:\n";
         foreach ($values as $fieldName => $value) {
             $test .= "{$fieldName}...";
             $boolFound = false;
             foreach ($this->getFields() as $f) {
                 if ($f->fieldname == $fieldName) {
                     $test .= " found. setfieldvalue:[{$value}]\n";
                     $f->setFieldValue($value);
                     $boolFound = true;
                     break;
                 }
             }
             if ($boolFound == false) {
                 $test .= " [not found]\n";
             }
         }
         Yii::log($test, "info");
     }
     parent::setAttributes($values);
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:27,代码来源:CrugeStoredUser.php

示例8: setAttributes

 /**
  * Sets the attribute and flags values in a massive way.
  * @param array $values attribute values (name=>value) to be set.
  * @param boolean $safeOnly whether the assignments should only be done to the safe attributes.
  * A safe attribute is one that is associated with a validation rule in the current {@link scenario}.
  * @see getSafeAttributeNames
  * @see attributeNames
  */
 public function setAttributes($values, $safeOnly = true)
 {
     $flags = $this->cachedFlags();
     $notFlags = array();
     foreach ($values as $key => $val) {
         if (array_key_exists($key, $flags)) {
             $this->setFlag($key, $val);
         } else {
             $notFlags[$key] = $val;
         }
     }
     parent::setAttributes($notFlags, $safeOnly);
 }
开发者ID:fduch2k,项目名称:yii-flagged-activerecord,代码行数:21,代码来源:TSFlaggedActiveRecord.php

示例9: setAttributes

 public function setAttributes($values, $safeOnly = null)
 {
     if ($safeOnly === null) {
         $safeOnly = $this->setOnlySafeAttributes;
     }
     return parent::setAttributes($values, $safeOnly);
 }
开发者ID:alsvader,项目名称:hackbanero,代码行数:7,代码来源:SmartAR++.php

示例10: copyAttributes

 /**
  * Copies attributes from one active record to another, skips primary key.
  * 
  * @param CActiveRecord $from                record to copy from
  * @param CActiveRecord $to                  record to copy to
  * @param array         $skipAttributes      attribute names which should not be copied
  * @param array         $forceCopyAttributes attribute names which should be force copied
  */
 protected static function copyAttributes($from, $to, $skipAttributes = array(), $forceCopyAttributes = array())
 {
     $attributes = $from->getAttributes();
     $pk = $to->getMetaData()->tableSchema->primaryKey;
     if (!is_array($pk)) {
         $skipAttributes[] = $pk;
     } else {
         $skipAttributes = array_merge($skipAttributes, $pk);
     }
     $skipAttributes = array_diff($skipAttributes, $forceCopyAttributes);
     foreach ($skipAttributes as $attribute) {
         unset($attributes[$attribute]);
     }
     $to->setAttributes($attributes, true);
 }
开发者ID:hansenmakangiras,项目名称:disperindag,代码行数:23,代码来源:CopyBehavior.php


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