当前位置: 首页>>代码示例>>PHP>>正文


PHP CActiveRecordBehavior::beforeSave方法代码示例

本文整理汇总了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);
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:11,代码来源:ASluggable.php

示例2: beforeSave

 public function beforeSave($event)
 {
     if ($this->_value !== NULL) {
         $this->getOwner()->setAttribute($this->getBackupAttribute(), $this->_value);
     }
     return parent::beforeSave($event);
 }
开发者ID:sinelnikof,项目名称:yiiext,代码行数:7,代码来源:ELastValueBehavior.php

示例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);
 }
开发者ID:Aplay,项目名称:Fastreview_site,代码行数:11,代码来源:SortableBehavior.php

示例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);
 }
开发者ID:cornernote,项目名称:yii-dressing,代码行数:11,代码来源:YdDefaultAttributesBehavior.php

示例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);
 }
开发者ID:Lucerin,项目名称:Yii-projects,代码行数:9,代码来源:SortableBehavior.php

示例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);
 }
开发者ID:wanyos2005,项目名称:hsbf,代码行数:10,代码来源:UserBehavior.php

示例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());
     }
 }
开发者ID:nurirahmat,项目名称:Yii-Extensions,代码行数:10,代码来源:YouTubeVideo.php

示例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;
 }
开发者ID:ranvirp,项目名称:rdp,代码行数:11,代码来源:P3MetaDataBehavior.php

示例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);
 }
开发者ID:nizsheanez,项目名称:documentation,代码行数:12,代码来源:FileManagerBehavior.php

示例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);
 }
开发者ID:ema394,项目名称:gestionale,代码行数:15,代码来源:myDateFormat.php

示例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;
 }
开发者ID:nurirahmat,项目名称:Yii-Extensions,代码行数:12,代码来源:HasImage.php

示例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);
 }
开发者ID:LumbaJack,项目名称:Mercado-BTX,代码行数:18,代码来源:ECryptBehavior.php

示例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;
         }
     }
 }
开发者ID:lidijakralj,项目名称:bober,代码行数:15,代码来源:GalleryBehavior.php

示例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);
 }
开发者ID:nizsheanez,项目名称:documentation,代码行数:14,代码来源:TimestampBehavior.php

示例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);
 }
开发者ID:buildshop,项目名称:bs-common,代码行数:18,代码来源:SortableCActiveRecordBehavior.php


注:本文中的CActiveRecordBehavior::beforeSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。