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


PHP ActiveRecord::findOne方法代碼示例

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


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

示例1: init

 public function init()
 {
     parent::init();
     $this->target = Yii::createObject($this->targetClass);
     if (!$this->condition) {
         $this->target = $this->target->findOne($this->condition);
     }
 }
開發者ID:shuangjie,項目名稱:galaxy,代碼行數:8,代碼來源:RecordBehavior.php

示例2: _delete

 protected function _delete(ActiveRecord $model)
 {
     $id = Yii::$app->request->post('id');
     $model->findOne($id)->delete();
     //        $model::deleteAll($id);
     return $this->_success();
 }
開發者ID:nisnaker,項目名稱:yii2-template,代碼行數:7,代碼來源:Base.php

示例3: getIdByName

 /**
  * @param $name
  * @return null|static
  */
 public static function getIdByName($name)
 {
     $branch = parent::findOne(['branch_title' => $name]);
     if ($branch) {
         return $branch->id;
     } else {
         return 0;
     }
 }
開發者ID:Griff19,項目名稱:it_base,代碼行數:13,代碼來源:Branches.php

示例4: findByUsername

 public static function findByUsername($username)
 {
     return parent::findOne(['username' => $username]);
 }
開發者ID:Crocodile26,項目名稱:php-1,代碼行數:4,代碼來源:Users.php

示例5: info

 public static function info()
 {
     return parent::findOne(\Yii::$app->user->getId());
 }
開發者ID:Crocodile26,項目名稱:php-1,代碼行數:4,代碼來源:Profile.php

示例6: findByLabel

 /**
  * Find model by label value
  * @param ActiveRecord $model
  * @param string $label
  * @return null|static
  */
 public static function findByLabel(ActiveRecord $model, $label)
 {
     /* @var ActiveRecord $this */
     return $model->findOne([self::getLabelColumnName($model) => $label]);
 }
開發者ID:vladdnepr,項目名稱:yii2-ycm,代碼行數:11,代碼來源:ModelHelper.php

示例7: findIdentity

 /**
  * @param string $id
  * @return User
  */
 public static function findIdentity($id)
 {
     return parent::findOne(['id' => $id]);
 }
開發者ID:kissarat,項目名稱:yii2-template,代碼行數:8,代碼來源:User.php

示例8: randomName

 /**
  * @return string
  * Create random file name. Override this if you need another name generation.
  * This function returns a random combination of six number characters and lower case letters,
  * allowing for 2 billion file names.
  */
 protected function randomName()
 {
     do {
         $r = base_convert(mt_rand(60466176, mt_getrandmax()), 10, 36);
         // 60466176 = 36^5; ensure six characters
     } while ($this->_model->findOne(['like', $this->attribute, $r . '%', false]));
     // ensure unique
     return $r;
 }
開發者ID:sjaakp,項目名稱:yii2-illustrated-behavior,代碼行數:15,代碼來源:Illustration.php

示例9: findByName

 public static function findByName($name)
 {
     return parent::findOne(['name' => $name, 'uid' => \Yii::$app->config->superId]);
 }
開發者ID:Crocodile26,項目名稱:php-1,代碼行數:4,代碼來源:Category.php

示例10: findByCache

 /**
  * 根據主鍵獲取記錄(支持緩存)
  * @param $key  主鍵值
  * @param $array 是否返回數組
  * @param $forceDb 是否強製從數據庫獲取
  */
 public static function findByCache($key, $array = true, $forceDb = false)
 {
     if (static::$pk) {
         if ($forceDb) {
             if (!$array) {
                 return parent::findOne([static::$pk => $key]);
             } else {
                 return parent::find()->where([static::$pk => $key])->asArray()->one();
             }
         } else {
             if (self::enableCache()) {
                 $cacheInstantce = static::getCache();
                 if (!$array) {
                     return parent::findOne([static::$pk => $key]);
                 } else {
                     $cache_key = self::getCacheKey($key, $array);
                     Yii::trace('from cache array:' . $cache_key, __METHOD__);
                     $row = $cacheInstantce->get($cache_key);
                     if ($row) {
                         return $row;
                     }
                     $row = parent::find()->where([static::$pk => $key])->asArray()->one();
                     if ($row) {
                         if ($cacheInstantce->exists($cache_key)) {
                             $cacheInstantce->set($cache_key, $row, isset(Yii::$app->params['ttl']) ? Yii::$app->params['ttl'] : 2592000);
                         } else {
                             $cacheInstantce->add($cache_key, $row, isset(Yii::$app->params['ttl']) ? Yii::$app->params['ttl'] : 2592000);
                         }
                     }
                     return $row;
                 }
             } else {
                 throw new Exception('cache undefined');
             }
         }
     } else {
         throw new Exception('primary key undefined');
     }
 }
開發者ID:highestgoodlikewater,項目名稱:yii2-liuxy-extension,代碼行數:45,代碼來源:ActiveRecord.php


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