public function get($code) { if (!$code) { return; } $setting = \strochkov\setting\models\Setting::find()->where(['code' => $code])->one(); if ($setting) { return $setting->value; } else { return; } }
public function actionIndex() { //if(!Yii::$app->user->can('readPost')) throw new HttpException(403, 'No Auth'); if (Yii::$app->request->isPost) { $setting = Yii::$app->request->post('Setting'); foreach ($setting as $key => $value) { Setting::updateAll(['value' => $value], ['code' => $key]); } } $settingParent = Setting::find()->where(['parent_id' => 0])->orderBy(['sort_order' => SORT_ASC])->all(); return $this->render('index', ['settingParent' => $settingParent]); }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use strochkov\setting\models\Setting; use strochkov\setting\Module; $this->title = Module::t('setting', 'Setting'); $this->params['breadcrumbs'][] = $this->title; $items = []; foreach ($settingParent as $parent) { $item['label'] = Module::t('setting', $parent->code); $str = ''; $children = Setting::find()->where(['parent_id' => $parent->id])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all(); foreach ($children as $child) { $str .= '<div class="form-group field-blogcatalog-parent_id"><label class="col-lg-2 control-label" for="blogcatalog-parent_id">' . Module::t('setting', $child->code) . '</label><div class="col-lg-3">'; if ($child->type == 'text') { $str .= Html::textInput("Setting[{$child->code}]", $child->value, ["class" => "form-control"]); } elseif ($child->type == 'password') { $str .= Html::passwordInput("Setting[{$child->code}]", $child->value, ["class" => "form-control"]); } elseif ($child->type == 'select') { $options = []; $arrayOptions = explode(',', $child->store_range); foreach ($arrayOptions as $option) { $options[$option] = Module::t('setting', $option); } $str .= Html::dropDownList("Setting[{$child->code}]", $child->value, $options, ["class" => "form-control"]); } $str .= '</div></div>'; } $item['content'] = $str;