本文整理汇总了PHP中yii\db\ActiveRecord::isAttributeChanged方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::isAttributeChanged方法的具体用法?PHP ActiveRecord::isAttributeChanged怎么用?PHP ActiveRecord::isAttributeChanged使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::isAttributeChanged方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isAttributeChanged
public function isAttributeChanged($name)
{
if ($name == 'picUrl') {
return $this->_old_picUrl != $this->picUrl;
}
return parent::isAttributeChanged($name);
}
示例2: isAttributeChanged
/**
* @param string $name
* @param bool $identical
*
* @return bool
*/
public function isAttributeChanged($name, $identical = true)
{
if (in_array($name, $this->getMultiLangFields())) {
$language = \Yii::$app->language;
$name = $this->buildMultilangFieldName($name, $language);
}
return parent::isAttributeChanged($name, $identical);
}
示例3: 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;
}
示例4: 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;
}
}
}
}
}