当前位置: 首页>>代码示例>>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;未经允许,请勿转载。