本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例6: getAttributes
public function getAttributes()
{
$attr = parent::getAttributes();
$attr['pingicon'] = $this->pingicon;
return $attr;
}
示例7: afterUpdate
public function afterUpdate()
{
TimelineEvent::log($this->owner->className(), 'afterUpdate', ['attributes' => $this->owner->getAttributes(), 'uid' => Yii::$app->user->identity->id]);
return true;
}
示例8: populateAttributes
/**
* Populate attributes value
*/
public function populateAttributes()
{
$attributes = array_intersect_key($this->_source->getAttributes(), $this->getAttributes());
$this->setAttributes($attributes, false);
}
示例9: init
public function init()
{
parent::init();
self::getConfig();
self::$_modelFields = array_keys(parent::getAttributes());
XiiVersion::run(self::XII_VERSION);
}