This method is internally called by [[findOne()]] and [[findAll()]].
protected static findByCondition ( mixed $condition ) : yii\db\ActiveQueryInterface | ||
$condition | mixed | please refer to [[findOne()]] for the explanation of this parameter |
Результат | yii\db\ActiveQueryInterface | the newly created [[ActiveQueryInterface|ActiveQuery]] instance. |
/** * 查找单个对象记录,支持主键缓存获取 * @param mixed $condition * @return mixed|null|static */ public static function findByCondition($condition) { if (isset($condition[static::$pk])) { $cache_key = self::getCacheKey($condition[static::$pk], false); Yii::trace('from cache object:' . $cache_key, __METHOD__); if (self::allowFromCache($condition)) { $row = Yii::$app->cache->get($cache_key); if ($row) { return $row; } } } $row = parent::findByCondition($condition); if ($row && isset($condition[static::$pk]) && self::allowFromCache($condition)) { if (Yii::$app->cache->exists($cache_key)) { Yii::$app->cache->set($cache_key, $row, Yii::$app->params['ttl']); } else { Yii::$app->cache->add($cache_key, $row, Yii::$app->params['ttl']); } } return $row; }