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


PHP ActiveRecord::getAttributes方法代码示例

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


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

示例1: searchQuery

 /**
  * @param ActiveRecord $model
  * @param array $opts
  * @return ActiveQuery | array
  */
 static function searchQuery($model, $opts = [])
 {
     $opts = ArrayHelper::merge(['data' => null, 'query' => null, 'columns' => [], 'filters' => []], $opts);
     $columns = $opts['columns'];
     $filters = $opts['filters'];
     $data = $opts['data'];
     if (null === $data) {
         $data = \Yii::$app->request->get();
     }
     $query = $opts['query'];
     if (is_string($query)) {
         $query = call_user_func([$model, $opts['query']]);
     } elseif (null === $query) {
         $query = $model->find();
         foreach (array_filter($model->getAttributes()) as $prop => $val) {
             $query->andWhere([$prop => $val]);
         }
     }
     if ($model->load($data) && $model->validate()) {
         foreach ($model->getAttributes($model->safeAttributes()) as $name => $value) {
             if ($model->isAttributeChanged($name)) {
                 $attributeTypes = [];
                 if (method_exists($model, 'attributeTypes')) {
                     $attributeTypes = $model->attributeTypes();
                 }
                 $type = null;
                 if (isset($attributeTypes[$name])) {
                     $type = $attributeTypes[$name];
                 }
                 // Default filter function
                 $filterFunc = isset($filters[$name]) && is_callable($filters[$name]) ? $filters[$name] : function (ActiveQuery $query, $name, $value, $type) {
                     /**
                      * @var string $name
                      * @var string|array $value
                      * @var string $type
                      */
                     $query->andFilterWhere(static::searchAttribute($name, $value, $type));
                 };
                 if (isset($columns[$name])) {
                     $name = $columns[$name];
                 }
                 call_user_func($filterFunc, $query, $name, $value, $type);
             }
         }
     }
     return $query;
 }
开发者ID:goodizer,项目名称:yii2-helpers,代码行数:52,代码来源:GridSearchHelper.php

示例2: castModel

 /**
  * Get an array representing the properties of a model.
  *
  * @param \yii\db\ActiveRecord $model
  * @return array
  */
 public static function castModel(ActiveRecord $model)
 {
     $attributes = array_merge($model->getAttributes(), $model->getRelatedRecords());
     $results = [];
     foreach ($attributes as $key => $value) {
         $results[Caster::PREFIX_VIRTUAL . $key] = $value;
     }
     return $results;
 }
开发者ID:yiisoft,项目名称:yii2-shell,代码行数:15,代码来源:YiiCaster.php

示例3: storeDataRecord

 /**
  * Store data record and track change statistics
  *
  * @param ActiveRecord $ActiveRecord
  *
  * @return bool false if not saved
  */
 protected function storeDataRecord(ActiveRecord $ActiveRecord)
 {
     if ($ActiveRecord->getDirtyAttributes()) {
         $unsaved_record = clone $ActiveRecord;
         // Save record
         if (!$ActiveRecord->save()) {
             // Create error message
             $message = "Save error: " . json_encode($ActiveRecord->errors) . "\n";
             $message .= "Record data: " . json_encode($ActiveRecord->getAttributes()) . "\n";
             trigger_error($message, E_USER_WARNING);
             $this->incStat('error_' . $ActiveRecord->tableName());
             return false;
         }
         // Store statistics
         if ($unsaved_record->isNewRecord) {
             $this->incStat('new_' . $ActiveRecord->tableName());
         } else {
             $this->incStat('update_' . $ActiveRecord->tableName());
         }
     }
     return true;
 }
开发者ID:drsdre,项目名称:yii2-betssonsports,代码行数:29,代码来源:Cache.php

示例4: getFormElements

 /**
  * Format same as kartik\builder\Form::$attributes
  * @param ActiveRecord $model
  * @return array
  *
  * @see kartik\builder\Form::$attributes
  */
 public function getFormElements($model)
 {
     $res = [];
     $attributes = $model->getAttributes();
     foreach ($model->getTableSchema()->primaryKey as $pk) {
         unset($attributes[$pk]);
     }
     $attributes = array_keys($attributes);
     foreach ($attributes as $attribute) {
         $res[$attribute]['type'] = Form::INPUT_TEXT;
     }
     $res[] = $this->getActionRow($model);
     return $res;
 }
开发者ID:e96,项目名称:yii2-madmin,代码行数:21,代码来源:MAdminController.php

示例5: dropCaches

 /**
  * @param ActiveRecord $model
  * @param array        $changedAttributes
  */
 public static function dropCaches($model, array $changedAttributes = [])
 {
     self::initialize();
     $attrs = $model->getAttributes();
     $changed = [];
     if ($changedAttributes) {
         $attrNames = array_keys($changedAttributes);
         foreach ($attrNames as $attrName) {
             if (array_key_exists($attrName, $attrs)) {
                 $changed[$attrName] = $attrs[$attrName];
             }
         }
     }
     $args = [$model->tableName(), json_encode($attrs, self::$jsonOptions), json_encode($changed, self::$jsonOptions)];
     CacheHelper::evalSHA(self::$shaInvalidate, $args, 0);
 }
开发者ID:sitkoru,项目名称:yii2-ar-cache,代码行数:20,代码来源:ActiveQueryCacheHelper.php

示例6: getAttributes

 public function getAttributes()
 {
     $attr = parent::getAttributes();
     $attr['pingicon'] = $this->pingicon;
     return $attr;
 }
开发者ID:RyosukeMurai,项目名称:TokyoSearch,代码行数:6,代码来源:Instagram.php

示例7: afterUpdate

 public function afterUpdate()
 {
     TimelineEvent::log($this->owner->className(), 'afterUpdate', ['attributes' => $this->owner->getAttributes(), 'uid' => Yii::$app->user->identity->id]);
     return true;
 }
开发者ID:allhaze,项目名称:renault,代码行数:5,代码来源:ChangeLogBehavior.php

示例8: populateAttributes

 /**
  * Populate attributes value
  */
 public function populateAttributes()
 {
     $attributes = array_intersect_key($this->_source->getAttributes(), $this->getAttributes());
     $this->setAttributes($attributes, false);
 }
开发者ID:voskobovich,项目名称:yii2-base-toolkit,代码行数:8,代码来源:FindableFormAbstract.php

示例9: init

 public function init()
 {
     parent::init();
     self::getConfig();
     self::$_modelFields = array_keys(parent::getAttributes());
     XiiVersion::run(self::XII_VERSION);
 }
开发者ID:keigonec,项目名称:EricXie-Xii2,代码行数:7,代码来源:XiiArPlus.php


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