本文整理汇总了PHP中yii\db\ActiveRecord::updateAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::updateAttributes方法的具体用法?PHP ActiveRecord::updateAttributes怎么用?PHP ActiveRecord::updateAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::updateAttributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterInsert
/**
* After insert event.
*/
public function afterInsert()
{
foreach ($this->attributes as $attribute => $storageConfig) {
if ($this->_files[$attribute] instanceof UploadedFile) {
if ($filePath = $this->saveFile($this->_files[$attribute], $storageConfig)) {
$this->owner->updateAttributes([$attribute => pathinfo($filePath, PATHINFO_BASENAME)]);
}
} elseif (is_array($this->_files[$attribute]) && !empty($this->_files[$attribute])) {
$paths = $this->saveFiles((array) $this->_files[$attribute], $storageConfig);
if ($paths) {
foreach ($paths as $key => $path) {
$paths[$key] = pathinfo($path, PATHINFO_BASENAME);
}
$this->owner->updateAttributes([$attribute => json_encode($paths)]);
}
}
}
}
示例2: updateOwner
/**
* @param integer $fileId
* @return int
* @throws Exception
*/
protected function updateOwner($fileId)
{
$this->owner->updateAttributes([$this->attribute => $fileId]);
$sql = "\n UPDATE " . $this->owner->tableName() . "\n SET " . $this->attribute . " = :file\n WHERE id = :id\n ";
return Yii::$app->db->createCommand($sql)->bindValue(':file', $fileId)->bindValue(':id', $this->owner->primaryKey)->execute();
}
示例3: updateAttributesInternal
/**
* Updates attributes for the given model.
*
* @param ActiveRecord $model model instance.
* @param array $attributes model attributes.
* @return boolean the result.
*/
protected function updateAttributesInternal(ActiveRecord $model, array $attributes)
{
return $model->updateAttributes($attributes) !== 0;
}