Exemplo n.º 1
0
 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]);
         }
         Yii::$app->setting->clearCache();
         Yii::$app->getSession()->setFlash('success', 'Save successfully.');
     }
     $settingParent = Setting::find()->where(['parent_id' => 0])->orderBy(['sort_order' => SORT_ASC])->all();
     return $this->render('index', ['settingParent' => $settingParent]);
 }
Exemplo n.º 2
0
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use shiyang\setting\models\Setting;
use shiyang\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;