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


PHP CActiveRecordBehavior類代碼示例

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


在下文中一共展示了CActiveRecordBehavior類的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: attach

 /**
  * @param CActiveRecord $owner
  */
 public function attach($owner)
 {
     $validator = new yupe\components\validators\NumberValidator();
     $validator->attributes = array($this->priceAttribute, $this->priceEurAttribute, $this->priceOldAttribute);
     $owner->getValidatorList()->add($validator);
     parent::attach($owner);
 }
開發者ID:kuzmina-mariya,項目名稱:unizaro-decor,代碼行數:10,代碼來源:PriceBehavior.php

示例3: attach

 /**
  * @param CActiveRecord $owner
  */
 public function attach($owner)
 {
     $validator = new CSafeValidator();
     $validator->attributes = array($this->attribute);
     $owner->getValidatorList()->add($validator);
     parent::attach($owner);
 }
開發者ID:kuzmina-mariya,項目名稱:gallery,代碼行數:10,代碼來源:DMultiplyListBehavior.php

示例4: afterValidate

 public function afterValidate($event)
 {
     parent::afterValidate($event);
     if ($this->checkScenario() && !$this->owner->hasErrors()) {
         $modelName = get_class($this->owner);
         if (isset($_FILES[$modelName]['name'][$this->attributeName])) {
             $files = array();
             foreach ($_FILES[$modelName] as $k => $v) {
                 $files[$k] = $v[$this->attributeName];
             }
             // Сохраняю
             if ($files) {
                 Yii::import('ext.ImageUpload.ImageUpload');
                 $handle = new ImageUpload($files);
                 if ($handle->uploaded) {
                     $this->saveImage($handle);
                     // Удаляю старую фотку
                     if ($this->owner->scenario == 'update') {
                         $this->deleteImage();
                     }
                     $handle->clean();
                 }
                 unset($handle, $files);
             }
         }
     }
 }
開發者ID:mmorpg2015,項目名稱:ghtweb5,代碼行數:27,代碼來源:ImageUploadBehavior.php

示例5: attach

 public function attach($owner)
 {
     parent::attach($owner);
     $this->_hasCreateDate = $this->getOwner()->hasAttribute('createDate');
     $this->_hasLastUpdated = $this->getOwner()->hasAttribute('lastUpdated');
     $this->_hasLastActivity = $this->getOwner()->hasAttribute('lastActivity');
 }
開發者ID:tymiles003,項目名稱:X2CRM,代碼行數:7,代碼來源:X2TimestampBehavior.php

示例6: 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

示例7: attach

 /**
  * @param CComponent $owner
  */
 public function attach($owner)
 {
     $owner->attachEventHandler('onProductAdded', array($this, 'productAddedEvent'));
     $owner->attachEventHandler('onProductDeleted', array($this, 'productDeletedEvent'));
     $owner->attachEventHandler('onProductQuantityChanged', array($this, 'onProductQuantityChanged'));
     parent::attach($owner);
 }
開發者ID:kolbensky,項目名稱:rybolove,代碼行數:10,代碼來源:HistoricalBehavior.php

示例8: attach

 /**
  * Attaches dynamic relations.
  * 
  * @param CActiveRecord $owner owner
  * 
  * @see CBehavior::attach()
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $ownerClassName = get_class($owner);
     $metaData = $owner->getMetaData();
     $metaData->addRelation('parent', array(CActiveRecord::BELONGS_TO, $ownerClassName, $this->parentIdColumn));
 }
開發者ID:hansenmakangiras,項目名稱:disperindag,代碼行數:14,代碼來源:AdjacencyTreeBehavior.php

示例9: attach

 /**
  * (non-PHPdoc).
  * 
  * @see CBehavior::attach()
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if (!isset($this->defaultCounter)) {
         $this->defaultCounter = $this->counters[0];
     }
 }
開發者ID:hansenmakangiras,項目名稱:disperindag,代碼行數:12,代碼來源:ArCounterBehavior.php

示例10: 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

示例11: 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

示例12: beforeDelete

 public function beforeDelete($event)
 {
     foreach ($this->findAllAttaches() as $attach) {
         $attach->delete();
     }
     return parent::beforeDelete($event);
 }
開發者ID:nizsheanez,項目名稱:kur.ru,代碼行數:7,代碼來源:AttachmentBehavior.php

示例13: attach

 /**
  * Attaches the behavior object to the model.
  *
  * @param string $owner The component to which the behavior will be applied
  */
 public function attach($owner)
 {
     parent::attach($owner);
     if ($this->getModule() === null) {
         // Resolve the module
         if (isset($this->baseRoute)) {
             // Try to extract it from $baseRoute (old custom modules)
             $this->module = preg_replace('/\\/.*/', '', preg_replace('/^\\//', '', $this->baseRoute));
         } else {
             // Assume the model name is the same as the module/controller
             // (also true of custom modules)
             $this->module = strtolower(get_class($this->owner));
         }
     }
     if (!isset($this->baseRoute)) {
         $this->baseRoute = '/' . $this->module;
     }
     if (!isset($this->viewRoute)) {
         $this->viewRoute = $this->baseRoute;
     }
     if (Yii::app()->params->isMobileApp) {
         $this->viewRoute .= '/mobileView';
     }
     if (!isset($this->autoCompleteSource)) {
         $this->autoCompleteSource = $this->baseRoute . '/getItems?modelType=' . get_class($this->owner);
     }
 }
開發者ID:dsyman2,項目名稱:X2CRM,代碼行數:32,代碼來源:X2LinkableBehavior.php

示例14: detach

 public function detach($owner)
 {
     parent::detach($owner);
     $this->objectId = null;
     $this->objectType = null;
     $this->_oaa = null;
 }
開發者ID:vasiliy-pdk,項目名稱:aes,代碼行數:7,代碼來源:ObjectAuthAssignmentBehavior.php

示例15: attach

 public function attach($owner)
 {
     parent::attach($owner);
     $this->_model = $owner;
     $this->addRelations();
     $this->addSafeAttributes();
 }
開發者ID:hit-shappens,項目名稱:testapp,代碼行數:7,代碼來源:ExtendedARBehavior.php


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