本文整理匯總了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;
}