本文整理汇总了PHP中CActiveRecordBehavior::beforeSave方法的典型用法代码示例。如果您正苦于以下问题:PHP CActiveRecordBehavior::beforeSave方法的具体用法?PHP CActiveRecordBehavior::beforeSave怎么用?PHP CActiveRecordBehavior::beforeSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActiveRecordBehavior
的用法示例。
在下文中一共展示了CActiveRecordBehavior::beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
/**
* Triggered before the model saves, this is where the slug attribute is actually set
* @see CActiveRecordBehavior::beforeSave()
*/
public function beforeSave($event)
{
if ($this->owner->isNewRecord || $this->owner->{$this->slugAttribute} == "") {
$this->owner->{$this->slugAttribute} = $this->createSlug();
}
return parent::beforeSave($event);
}
示例2: beforeSave
public function beforeSave($event)
{
if ($this->_value !== NULL) {
$this->getOwner()->setAttribute($this->getBackupAttribute(), $this->_value);
}
return parent::beforeSave($event);
}
示例3: beforeSave
/**
* @param \CModelEvent $event
*/
public function beforeSave($event)
{
if ($this->getOwner()->getIsNewRecord()) {
$position = Yii::app()->getDb()->createCommand("select max({$this->attributeName}) from {$this->getOwner()->tableName()}")->queryScalar();
$this->getOwner()->{$this->attributeName} = (int) $position + 1;
}
return parent::beforeSave($event);
}
示例4: beforeSave
/**
* @param CModelEvent $event
*/
public function beforeSave($event)
{
if (method_exists($this->getOwner(), 'setDefaultAttributes')) {
$this->getOwner()->setDefaultAttributes();
}
// will the following will be called twice?
return parent::beforeSave($event);
}
示例5: beforeSave
public function beforeSave($event)
{
$model = $this->getOwner();
$column = $this->column;
if ($model->isNewRecord) {
$model->{$column} = Yii::app()->db->createCommand("SELECT MAX({$this->column}) FROM " . $model->tableName())->queryScalar() + 1;
}
parent::beforeSave($event);
}
示例6: beforeSave
public function beforeSave($event)
{
$owner = $this->getOwner();
//concatenate the salt with password
if ($owner->hasAttribute('password') && ($owner->getIsNewRecord() || $owner->getScenario() === Users::SCENARIO_CHANGE_PASSWORD || $owner->getScenario() === Users::SCENARIO_RESET_PASSWORD)) {
$owner->genericField = $owner->password;
$owner->password = $owner->salt . md5($owner->password);
}
return parent::beforeSave($event);
}
示例7: beforeSave
public function beforeSave($event)
{
parent::beforeSave($event);
if (!$this->owner->isNewRecord) {
list($utub, $video) = $this->getVideo();
$video->setVideoDescription($this->owner->description);
$video->setVideoTitle($this->owner->title);
$utub->updateEntry($video, $video->getEditLink()->getHref());
}
}
示例8: beforeSave
public function beforeSave($event)
{
parent::beforeSave($event);
if ($this->resolveMetaDataModel() !== null && $this->resolveMetaDataModel()->checkAccessUpdate) {
if (Yii::app()->user->checkAccess($this->resolveMetaDataModel()->checkAccessUpdate) === false) {
throw new CHttpException(403, "You are not authorized to perform this action. Access restricted by P3MetaDataBehavior.");
return false;
}
}
return true;
}
示例9: afterSave
public function afterSave($event)
{
$model = $this->getOwner();
if ($model->isNewRecord) {
$files = FileManager::model()->findAllByAttributes(array('object_id' => 'tmp_' . Yii::app()->user->id, 'model_id' => get_class($model)));
foreach ($files as $file) {
$file->object_id = $model->id;
$file->save();
}
}
return parent::beforeSave($event);
}
示例10: beforeSave
/**
* Convert from $dateFormat to ISO 9075 dates before saving
*/
public function beforeSave($event)
{
foreach ($this->dateColumns as $date) {
$_dt = $this->Owner->{$date};
if (preg_match("/([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{4})/", $_dt, $regs)) {
//var_dump($regs);
$_dt = $regs[3] . "-" . $regs[2] . "-" . $regs[1];
}
$this->Owner->{$date} = $_dt;
}
return parent::beforeSave($event);
}
示例11: beforeSave
public function beforeSave($event)
{
parent::beforeSave($event);
if (!$this->owner->isNewRecord) {
foreach ($this->fields as $field) {
if (!$this->owner->{$field}) {
$this->owner->{$field} = $this->owner->model()->findByPk($this->owner->primaryKey)->{$field};
}
}
}
return true;
}
示例12: beforeSave
/**
* Encrypts the value of specified attributes before saving to database
* @param CEvent $event
* @return parent::beforeSave
*/
public function beforeSave($event)
{
foreach ($this->getOwner()->getAttributes() as $key => $value) {
if (in_array($key, $this->attributes) && !empty($value)) {
if ($this->useAESMySql) {
$this->getOwner()->{$key} = $this->mysqlAESEncrypt($value, Yii::app()->securityManager->getEncryptionKey());
} else {
$this->getOwner()->{$key} = utf8_encode(Yii::app()->securityManager->encrypt($value));
}
}
}
return parent::beforeSave($event);
}
示例13: beforeSave
/** Will create new gallery after save if no associated gallery exists */
public function beforeSave($event)
{
parent::beforeSave($event);
if ($event->isValid) {
if (empty($this->getOwner()->{$this->idAttribute})) {
$gallery = new Gallery();
$gallery->name = $this->name;
$gallery->description = $this->description;
$gallery->versions = $this->versions;
$gallery->save();
$this->getOwner()->{$this->idAttribute} = $gallery->id;
}
}
}
示例14: beforeSave
public function beforeSave($event)
{
$model = $this->getOwner();
if ($model->isNewRecord) {
if (array_key_exists('date_create', $model->attributes)) {
$model->date_create = new CDbExpression('NOW()');
}
} else {
if (array_key_exists('date_update', $model->attributes)) {
$model->date_update = new CDbExpression('NOW()');
}
}
return parent::beforeSave($event);
}
示例15: beforeSave
/**
* Responds to {@link CActiveRecord::onBeforeSave} event.
* @param CModelEvent $event event parameter
*/
public function beforeSave($event)
{
$sender = $event->sender;
if ($sender->isNewRecord) {
$model = call_user_func(array(get_class($sender), 'model'));
$last_record = $model->find(array('order' => '`' . $this->orderField . '` DESC', 'limit' => 1));
if ($last_record) {
$sender->{$this->orderField} = $last_record->{$this->orderField} + 1;
} else {
$sender->{$this->orderField} = 1;
}
}
return parent::beforeSave($event);
}