當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CActiveRecordBehavior::afterSave方法代碼示例

本文整理匯總了PHP中CActiveRecordBehavior::afterSave方法的典型用法代碼示例。如果您正苦於以下問題:PHP CActiveRecordBehavior::afterSave方法的具體用法?PHP CActiveRecordBehavior::afterSave怎麽用?PHP CActiveRecordBehavior::afterSave使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CActiveRecordBehavior的用法示例。


在下文中一共展示了CActiveRecordBehavior::afterSave方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: afterSave

 public function afterSave($event)
 {
     parent::afterSave($event);
     // do not auto-create meta data information for meta data table itself (recursion).
     if ($this->metaDataRelation == '_self_') {
         return true;
     }
     // create new meta data record or just update modifiedBy/At columns
     if ($this->resolveMetaDataModel() === null) {
         $metaClassName = $this->owner->getActiveRelation($this->metaDataRelation)->className;
         $metaModel = new $metaClassName();
         $metaModel->id = $this->owner->id;
         $metaModel->status = self::STATUS_ACTIVE;
         $metaModel->language = Yii::app()->language;
         $metaModel->owner = Yii::app()->user->id;
         $primaryRole = key(Yii::app()->authManager->getRoles(Yii::app()->user->id));
         $metaModel->checkAccessDelete = $primaryRole;
         $metaModel->createdAt = date('Y-m-d H:i:s');
         $metaModel->createdBy = Yii::app()->user->id;
         $metaModel->model = get_class($this->owner);
     } else {
         $metaModel = $this->resolveMetaDataModel();
         $metaModel->modifiedAt = date('Y-m-d H:i:s');
         $metaModel->modifiedBy = Yii::app()->user->id;
     }
     $metaModel->save();
     return true;
 }
開發者ID:ranvirp,項目名稱:rdp,代碼行數:28,代碼來源:P3MetaDataBehavior.php

示例2: afterSave

 public function afterSave($event)
 {
     $relations = $this->getRelations();
     foreach ($relations as $relation) {
         if ($relation['type'] == CActiveRecord::MANY_MANY) {
             $forAdd = array_diff($relation['value'], $relation['oldValue']);
             foreach ($forAdd as $id) {
                 if ($id) {
                     $sql = 'INSERT INTO `' . $relation['m2mTable'] . '`
                                 (`' . $relation['m2mThisField'] . '`, `' . $relation['m2mForeignField'] . '`)
                         VALUES (:this_field, :foreign_field)';
                     Yii::app()->getDb()->createCommand($sql)->bindValues(array('this_field' => $this->getOwner()->id, ':foreign_field' => $id))->execute();
                 }
             }
             $forRemove = array_diff($relation['oldValue'], $relation['value']);
             foreach ($forRemove as $id) {
                 if ($id) {
                     $sql = 'DELETE IGNORE FROM `' . $relation['m2mTable'] . '`
                             WHERE `' . $relation['m2mThisField'] . '` = :this_field
                                AND `' . $relation['m2mForeignField'] . '` = :foreign_field';
                     Yii::app()->getDb()->createCommand($sql)->bindValues(array('this_field' => $this->getOwner()->id, ':foreign_field' => $id))->execute();
                 }
             }
         }
     }
     //Yii::app()->end();
     parent::afterSave($event);
     return true;
 }
開發者ID:rosko,項目名稱:Tempo-CMS,代碼行數:29,代碼來源:RelationsBehavior.php

示例3: afterSave

 public function afterSave($event)
 {
     if (Yii::app() instanceof CWebApplication) {
         if (Yii::app()->user->getState(UserIdentity::STATE_AUDIT_TRAIL, true)) {
             $isNewRecord = $this->getOwner()->getIsNewRecord();
             UserActivityLog::model()->addRecord(array('user_id' => Yii::app()->user->id, 'ip' => Common::getIp(), 'action' => $isNewRecord ? 'create' : 'update', 'activity' => $this->prepareString($isNewRecord ? $this->createTemplate : $this->updateTemplate)));
         }
     }
     return parent::afterSave($event);
 }
開發者ID:wanyos2005,項目名稱:hsbf,代碼行數:10,代碼來源:AuditTrailBehavior.php

示例4: afterSave

 public function afterSave($event)
 {
     return parent::afterSave($event);
     if ($this->owner->isNewRecord) {
         if (array_key_exists(get_class($this->owner), self::$handlers)) {
             $method = self::$handlers[get_class($this->owner)]['create'];
             $this->{$method}();
         }
     }
 }
開發者ID:JimmDiGriz,項目名稱:HGApi,代碼行數:10,代碼來源:PushBehavior.php

示例5: afterSave

 public function afterSave($event)
 {
     parent::afterSave($event);
     if (!$this->owner->isNewRecord) {
         $videoCache = Yii::app()->cache->get('Video::' . $this->owner->youtubeId);
         $videoCache['description'] = $this->owner->description;
         $videoCache['title'] = $this->owner->title;
         Yii::app()->cache->set('Video::' . $this->owner->youtubeId, $videoCache);
     }
 }
開發者ID:nurirahmat,項目名稱:Yii-Extensions,代碼行數:10,代碼來源:YouTubeVideo.php

示例6: afterSave

 public function afterSave($event)
 {
     $model = $this->getOwner();
     if ($model->isNewRecord) {
         foreach ($this->findAllAttaches() as $attach) {
             $attach->object_id = $model->id;
             $attach->save();
         }
     }
     return parent::afterSave($event);
 }
開發者ID:nizsheanez,項目名稱:kur.ru,代碼行數:11,代碼來源:AttachmentBehavior.php

示例7: afterSave

 /**
  * @param CEvent $event
  */
 public function afterSave($event)
 {
     // restore values of attributes saved in _convertAttributesToDB()
     if (count($this->_backupAttributes)) {
         foreach ($this->_backupAttributes as $name => $value) {
             $this->getOwner()->{$name} = $value;
         }
         $this->_backupAttributes = [];
     }
     parent::afterSave($event);
 }
開發者ID:ivko,項目名稱:yii-transform-attributes-behavior,代碼行數:14,代碼來源:TransformAttributesBehavior.php

示例8: afterSave

 public function afterSave($event)
 {
     $allowedFields = $this->allowed;
     $ignoredFields = $this->ignored;
     $ignoredClasses = $this->ignored_class;
     $newattributes = $this->getOwner()->getAttributes();
     $oldattributes = $this->getOldAttributes();
     // Lets check if the whole class should be ignored
     if (sizeof($ignoredClasses) > 0) {
         if (array_search(get_class($this->getOwner()), $ignoredClasses) !== false) {
             return;
         }
     }
     // Lets unset fields which are not allowed
     if (sizeof($allowedFields) > 0) {
         foreach ($newattributes as $f => $v) {
             if (array_search($f, $allowedFields) === false) {
                 unset($newattributes[$f]);
             }
         }
         foreach ($oldattributes as $f => $v) {
             if (array_search($f, $allowedFields) === false) {
                 unset($oldattributes[$f]);
             }
         }
     }
     // Lets unset fields which are ignored
     if (sizeof($ignoredFields) > 0) {
         foreach ($newattributes as $f => $v) {
             if (array_search($f, $ignoredFields) !== false) {
                 unset($newattributes[$f]);
             }
         }
         foreach ($oldattributes as $f => $v) {
             if (array_search($f, $ignoredFields) !== false) {
                 unset($oldattributes[$f]);
             }
         }
     }
     // If no difference then WHY?
     // There is some kind of problem here that means "0" and 1 do not diff for array_diff so beware: stackoverflow.com/questions/12004231/php-array-diff-weirdness :S
     if (count(array_diff_assoc($newattributes, $oldattributes)) <= 0) {
         return;
     }
     // If this is a new record lets add a CREATE notification
     if ($this->getOwner()->getIsNewRecord()) {
         $this->leaveTrail('CREATE');
     }
     // Now lets actually write the attributes
     $this->auditAttributes($newattributes, $oldattributes);
     // Reset old attributes to handle the case with the same model instance updated multiple times
     $this->setOldAttributes($this->getOwner()->getAttributes());
     return parent::afterSave($event);
 }
開發者ID:beckblurry,項目名稱:Yii1-Base-Core-V.Alpha.1,代碼行數:54,代碼來源:LoggableBehavior.php

示例9: afterSave

 public function afterSave($event)
 {
     $owner = $this->getOwner();
     if ($owner->getIsNewRecord() && $owner->send_email) {
         $this->accountDetailsEmail();
     }
     if ($owner->getScenario() === Users::SCENARIO_RESET_PASSWORD && $owner->send_email) {
         $this->newPasswordEmail();
     }
     if ($owner->getIsNewRecord() && $owner->getScenario() === Users::SCENARIO_SIGNUP) {
         $this->sendAccActivationEmail();
     }
     return parent::afterSave($event);
 }
開發者ID:wanyos2005,項目名稱:hsbf,代碼行數:14,代碼來源:UserBehavior.php

示例10: afterSave

 public function afterSave($event)
 {
     $attributes = Yii::app()->request->getParam('MetaTag');
     if ($attributes) {
         $meta_tag = MetaTag::model()->findByAttributes(array('object_id' => $this->owner->id, 'model_id' => get_class($this->owner)));
         if (!$meta_tag) {
             $meta_tag = new MetaTag();
         }
         $attributes['object_id'] = $this->owner->id;
         $attributes['model_id'] = get_class($this->owner);
         $meta_tag->attributes = $attributes;
         $meta_tag->save();
     }
     return parent::afterSave($event);
 }
開發者ID:nizsheanez,項目名稱:alp.ru,代碼行數:15,代碼來源:MetaTagBehavior.php

示例11: afterSave

 public function afterSave($event)
 {
     parent::afterSave($event);
     // Save all languages updated via setTranslatedFields().
     if ($this->autoSave) {
         foreach ($this->updates as $language => $callback) {
             $callback[0]->model_id = $this->owner->id;
             if (!call_user_func($callback)) {
                 throw new \Exception("Model callback failed.");
             }
         }
         if (isset($this->_current)) {
             $this->_current->save();
         }
     }
     $this->backupValues();
     if (isset($this->_current)) {
         $this->setLanguage($this->_current->language);
     }
 }
開發者ID:sam-it,項目名稱:yii1-translate,代碼行數:20,代碼來源:TranslatableBehavior.php

示例12: afterSave

 public function afterSave($event)
 {
     parent::afterSave($event);
     $this->processAttributes($event->sender, self::DIRECTION_CLIENT);
 }
開發者ID:kumar-akhmadiyev,項目名稱:yii-components,代碼行數:5,代碼來源:CDateTimeBehavior.php

示例13: afterSave

 /**
  * Provides saving related HAS_ONE records.
  * 
  * @param CEvent $event event object
  * 
  * @see CActiveRecordBehavior::afterSave()
  *
  * @throws Exception
  */
 public function afterSave($event)
 {
     $owner = $this->getOwner();
     foreach ($owner->relations() as $key => $relation) {
         $isHasOne = $relation['0'] == CActiveRecord::HAS_ONE;
         if (!$isHasOne) {
             continue;
         }
         if (isset($this->relations[$key]) || in_array($key, $this->relations)) {
             $config = $this->_getRelationConfig($key);
             $owner->{$key}->{$relation}[2] = $owner->primaryKey;
             if ($config['createRelated'] && !$owner->{$key}) {
                 $related = new $relation[1]();
                 $related->{$relation}[2] = $owner->primaryKey;
             } else {
                 $related = $owner->{$key};
             }
             if ($config['saveRelated'] && !$related->save()) {
                 $message = 'Can not save related record. ' . CHtml::errorSummary($related);
                 throw new CException($message);
             }
         }
     }
     parent::afterSave($event);
 }
開發者ID:hansenmakangiras,項目名稱:disperindag,代碼行數:34,代碼來源:CHasOneBehavior.php

示例14: afterSave

 /**
  * Сохраняем историю
  */
 public function afterSave($event)
 {
     parent::afterSave($event);
     if ($this->saveHistory && $this->waitForSave) {
         $table = $this->historyTable ? $this->historyTable : $this->owner->tableName() . "_events_history";
         $builder = Yii::app()->db->schema->commandBuilder;
         $builder->createMultipleInsertCommand($table, $this->waitForSave)->execute();
     }
 }
開發者ID:amanukian,項目名稱:test,代碼行數:12,代碼來源:CatchChangesBehavior.php

示例15: afterSave

 /**
  * Update model translations
  */
 public function afterSave($event)
 {
     Tag::model()->updateFrequency($this->_oldTags, $this->getOwner()->tags);
     return parent::afterSave($event);
 }
開發者ID:buildshop,項目名稱:bs-common,代碼行數:8,代碼來源:TagsBehavior.php


注:本文中的CActiveRecordBehavior::afterSave方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。