Ejemplo n.º 1
0
 /**
  * 修改option数据表
  * @param string $type
  * @return integer 影响的行数
  */
 public function replace($type)
 {
     $row = 0;
     foreach ($this->attributes as $name => $value) {
         if ($this->getOldAttribute($name) == $value) {
             continue;
         }
         $row += Yii::$app->db->createCommand("REPLACE INTO " . Option::tableName() . " (type, name, value) VALUES(:type,:name,:value)", [':type' => $type, ':name' => $name, ':value' => $value])->execute();
     }
     return $row;
 }
Ejemplo n.º 2
0
 /**
  * 获取Option信息
  * @param string $type 类型 默认为sys
  * @param bool $refresh 强制刷新
  * @return array $config 配置数组
  */
 public static function getSiteConfig($type = 'sys', $refresh = false)
 {
     $cache_key = "config_{$type}";
     if ($refresh) {
         $config = null;
     } else {
         $config = Yii::$app->cache->get($cache_key);
     }
     if (empty($config)) {
         $options = Option::find()->where(['type' => $type])->asArray()->all();
         foreach ($options as $op) {
             $config[$op['name']] = $op['value'];
         }
         $dp = new DbDependency();
         $dp->sql = (new Query())->select('MAX(update_time)')->from(Option::tableName())->createCommand()->rawSql;
         Yii::$app->cache->set($cache_key, $config, 3600, $dp);
     }
     return $config;
 }