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


PHP CActiveRecord::findByPk方法代碼示例

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


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

示例1: findByPk

 public function findByPk($pk, $condition = '', $params = array())
 {
     if ($pk === 0) {
         return self::getDefaultStore();
     } else {
         return parent::findByPk($pk, $condition, $params);
     }
 }
開發者ID:damnpoet,項目名稱:yiicart,代碼行數:8,代碼來源:Store.php

示例2: findByPk

 /**
  * 重寫findByPk方法
  */
 public function findByPk($pk, $condition = '', $params = array())
 {
     $key = $this->getCacheKey($pk);
     $cache = Yii::app()->cache->get($key);
     if ($cache === false) {
         $cache = parent::findByPk($pk, $condition, $params);
         Yii::app()->cache->set($key, $cache, $this->duration, $this->_getDependency());
     }
     return $cache;
 }
開發者ID:njz817,項目名稱:ycms,代碼行數:13,代碼來源:MasterActiveRecord.php

示例3: findByPk

 /**
  * 重寫findByPk方法,如果緩存存在數據,則直接讀取緩存
  * 在YiicmsActiveRecordBehavior中,一旦有數據更新則刪除緩存
  */
 public function findByPk($pk, $condition = '', $params = array())
 {
     $key = $this->getCacheKey($pk);
     //Yii::app()->cache->delete($key);
     $resource = Yii::app()->cache->get($key);
     if ($resource === false) {
         $resource = parent::findByPk($pk, $condition, $params);
         Yii::app()->cache->set($key, $resource, 3600);
         // 因為在緩存中沒找到,重新生成 $value
         // 再緩存一下以備下次使用
         // Yii::app()->cache->set($id,$value);
     }
     return $resource;
 }
開發者ID:vangogogo,項目名稱:justsns,代碼行數:18,代碼來源:YiicmsActiveRecord.php

示例4: update

 /**
  * main function called to update column in database
  *
  */
 public function update()
 {
     //get params from request
     $this->primaryKey = yii::app()->request->getParam('pk');
     $this->attribute = yii::app()->request->getParam('name');
     $this->value = yii::app()->request->getParam('value');
     $this->scenario = yii::app()->request->getParam('scenario');
     //checking params
     if (empty($this->attribute)) {
         throw new CException(Yii::t('EditableSaver.editable', 'Property "attribute" should be defined.'));
     }
     $this->model = new $this->modelClass();
     $isFormModel = $this->model instanceof CFormModel;
     $isMongo = EditableField::isMongo($this->model);
     if (empty($this->primaryKey) && !$isFormModel) {
         throw new CException(Yii::t('EditableSaver.editable', 'Property "primaryKey" should be defined.'));
     }
     //loading model
     if ($isMongo) {
         $this->model = $this->model->findByPk(new MongoID($this->primaryKey));
     } elseif (!$isFormModel) {
         $this->model = $this->model->findByPk($this->primaryKey);
     }
     if (!$this->model) {
         throw new CException(Yii::t('EditableSaver.editable', 'Model {class} not found by primary key "{pk}"', array('{class}' => get_class($this->model), '{pk}' => is_array($this->primaryKey) ? CJSON::encode($this->primaryKey) : $this->primaryKey)));
     }
     //keep parent model for mongo
     $originalModel = $this->model;
     //resolve model only for mongo! we should check attribute safety
     if ($isMongo) {
         $resolved = EditableField::resolveModels($this->model, $this->attribute);
         $this->model = $resolved['model'];
         //can be related model now
         $this->attribute = $resolved['attribute'];
         $staticModel = $resolved['staticModel'];
     } else {
         $staticModel = $this->model;
     }
     //set scenario for main model
     if ($this->scenario) {
         $originalModel->setScenario($this->scenario);
     }
     //is attribute safe
     if (!$this->model->isAttributeSafe($this->attribute)) {
         throw new CException(Yii::t('editable', 'Model {class} rules do not allow to update attribute "{attr}"', array('{class}' => get_class($this->model), '{attr}' => $this->attribute)));
     }
     //setting new value
     $this->setAttribute($this->attribute, $this->value);
     //validate attribute
     $this->model->validate(array($this->attribute));
     $this->checkErrors();
     //trigger beforeUpdate event
     $this->beforeUpdate();
     $this->checkErrors();
     //remove virtual attributes (which NOT in DB table)
     if (!$isMongo) {
         $this->changedAttributes = array_intersect($this->changedAttributes, $originalModel->attributeNames());
         if (count($this->changedAttributes) == 0) {
             //can not pass empty array in model->save() method!
             $this->changedAttributes = null;
         }
     }
     //saving (no validation, only changed attributes) note: for mongo save all!
     if ($isMongo) {
         $result = $originalModel->save(false, null);
     } elseif (!$isFormModel) {
         $result = $originalModel->save(false, $this->changedAttributes);
     } else {
         $result = true;
     }
     if ($result) {
         $this->afterUpdate();
     } else {
         $this->error(Yii::t('EditableSaver.editable', 'Error while saving record!'));
     }
 }
開發者ID:syukrikhafidh,項目名稱:appdefault,代碼行數:80,代碼來源:WhEditableSaver.php

示例5: findByPk

 /**
  *
  * @param mixed $pk
  * @param string $condition
  * @param array $params
  * @return CStubActiveRecord 
  */
 public function findByPk($pk, $condition = '', $params = array())
 {
     if (CStubActiveRecord::isUnittests()) {
         return CallFactory::call($this, 'findByPk');
     }
     return parent::findByPk($pk, $condition, $params);
 }
開發者ID:anton-itscript,項目名稱:WM-Web,代碼行數:14,代碼來源:CStubActiveRecord.php

示例6: findByPk

 public function findByPk($pk, $condition = '', $params = array())
 {
     if (empty($condition) && empty($params)) {
         if (array_key_exists($pk, $this->findByPkCache)) {
             return $this->findByPkCache[$pk];
         } else {
             $result = parent::findByPk($pk, $condition, $params);
             if (!is_null($result)) {
                 $this->findByPkCache[$pk] = $result;
             }
             return $result;
         }
     }
     return parent::findByPk($pk, $condition, $params);
 }
開發者ID:ryu1inaba,項目名稱:LimeSurvey,代碼行數:15,代碼來源:Survey.php

示例7: findByPk

 public function findByPk($pk, $condition = '', $params = array())
 {
     return $this->prepareRecord(parent::findByPk($pk, $this->prepareCondition($condition), $params));
 }
開發者ID:kuzmina-mariya,項目名稱:unizaro-spa,代碼行數:4,代碼來源:EavActiveRecord.php

示例8: findByPk

 /**
  * @see CActiveRecord::findByPk()
  * @return CEntity
  */
 public function findByPk($pk, $condition = '', $params = array())
 {
     $this->setDbReading();
     if (($result = $this->readFromCache($pk)) !== false) {
         $this->setReadingFromCache();
         $record = $this->populateRecord($result, true);
         $this->resetReadingFromCache();
         return $record;
     } else {
         $this->resetReadingFromCache();
         return parent::findByPk($pk);
     }
 }
開發者ID:njxjxj,項目名稱:yorm,代碼行數:17,代碼來源:CEntity.php


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