本文整理汇总了PHP中EMongoDocument::update方法的典型用法代码示例。如果您正苦于以下问题:PHP EMongoDocument::update方法的具体用法?PHP EMongoDocument::update怎么用?PHP EMongoDocument::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EMongoDocument
的用法示例。
在下文中一共展示了EMongoDocument::update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Updates the row represented by this active record.
* All loaded attributes will be saved to the database.
* Note, validation is not performed in this method. You may call {@link validate} to perform the validation.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the update is successful
* @throws EMongoException if the record is new
* @since v1.3
*/
public function update(array $attributes = null, $modify = false)
{
Yii::trace('Trace: ' . __CLASS__ . '::' . __FUNCTION__ . '()', 'ext.MongoDb.EMongoGridFS');
if ($this->getIsNewRecord()) {
throw new EMongoException(Yii::t('yii', 'The EMongoDocument cannot be updated because it is new.'));
}
if (is_file($this->filename) === true) {
if ($this->deleteByPk($this->_id) !== false) {
$result = $this->insertWithPk($this->_id, $attributes);
if ($result === true) {
return true;
} else {
return false;
}
}
} else {
return parent::update($attributes, true);
}
}
示例2: update
/**
* Updates the row represented by this active record.
* All loaded attributes will be saved to the database.
* Note, validation is not performed in this method. You may call {@link validate} to perform the validation.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @param boolean modify if set true only selected attributes will be replaced, and not
* the whole document
* @return boolean whether the update is successful
* @throws CException if the record is new
* @throws EMongoException on fail of update
* @throws MongoCursorException on fail of update, when safe flag is set to true
* @throws MongoCursorTimeoutException on timeout of db operation , when safe flag is set to true
* @since v1.0
*/
public function update(array $attributes = null, $modify = false)
{
if ($this->_partial) {
$attributes = count($attributes) > 0 ? array_intersect($attributes, $this->_loadedFields) : array_diff($this->_loadedFields, array('_id'));
return parent::update($attributes, true);
}
return parent::update($attributes, $modify);
}