protected function findModel($id) { if (($model = Config::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getValue($id, $defaultValue = '') { $model = Config::findOne(['id' => $id]); if ($model == null || empty($model['value'])) { return $defaultValue; } return $model['value']; }
protected function saveItem($id, $value) { $exist = Config::findOne($id); if ($exist) { Config::updateAll(['value' => $value], ['id' => $id]); } else { $model = new Model(); $model->scope = $this->scope; $model->id = $id; $model->value = $value; $model->description = $id; $model->save(); } }
use common\includes\CommonUtility; /** * @var yii\web\View $this * @var app\models\Content $model * @var yii\widgets\ActiveForm $form */ $this->registerJsFile('static/common/js/common.js'); $formatArray = CommonUtility::getTitleFormat(); $formatValueArray = CommonUtility::getTitleFormatArray($model); $contentFlags = CommonUtility::getFlag(); $att1Lable = Config::getValue('content_att1_label', '属性1'); $att1Array = Config::getContentAtt('content_att1_name'); $att2Lable = Config::getValue('content_att2_label', '属性2'); $att2Array = Config::getContentAtt('content_att2_name'); $att3Lable = Config::getValue('content_att3_label', '属性3'); $att3Array = Config::getContentAtt('content_att3_name'); ?> <input type="hidden" id="content-channel_id" class="form-control" name="Content[channel_id]" value="<?php echo $chnid; ?> "> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 128]); ?> <tr class="form-group field-content-title_format"> <td class="hAlign_right padding_r10"> <label style="font-weight:normal;" for="content-title_format">标题格式</label>:</td> <td> <?php
public static function createConfigCache() { self::createCacheFile(); $content = '<?php' . self::$newLine; $dataList = Config::findAll(); foreach ($dataList as $row) { $id = $row['id']; $content .= '$cachedConfigs[\'' . $row['id'] . '\']=[' . self::$newLine; $content .= self::getCacheItem('id', $row); $content .= self::getCacheItem('scope', $row); $content .= self::getCacheItem('value', $row); $content .= self::getCacheItem('note', $row); $content .= "];" . self::$newLine; } self::writeFile('cachedConfigs.php', $content); }