public function actionLogo()
 {
     $model = Setting::find()->where(['name' => 'logo'])->one();
     if ($model === null || $model->visibility < (IS_ROOT ? Setting::VISIBLE_ROOT : Setting::VISIBLE_ALL)) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/settings']);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_POST['Setting']['value'])) {
                 $model->value = UploadedFile::getInstance($model, 'value');
                 if ($model->value) {
                     $model->value = Image::uploadLogo($model->value, 'logo', false);
                 } else {
                     $model->value = '';
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii', 'Setting updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('logo', ['model' => $model]);
     }
 }
Esempio n. 2
0
 public static function logo()
 {
     $logo = Setting::find()->where(['name' => 'logo'])->one();
     if (isset($logo) && $logo->value) {
         return $logo;
     } else {
         return false;
     }
 }
Esempio n. 3
0
 public static function set($name, $value)
 {
     if (self::get($name)) {
         $setting = Setting::find()->where(['name' => $name])->one();
         $setting->value = $value;
     } else {
         $setting = new Setting(['name' => $name, 'value' => $value, 'title' => $name, 'visibility' => self::VISIBLE_NONE]);
     }
     $setting->save();
 }
 public function actionIndex()
 {
     $data = new ActiveDataProvider(['query' => Setting::find()->where(['>=', 'visibility', IS_ROOT ? Setting::VISIBLE_ROOT : Setting::VISIBLE_ALL])]);
     Yii::$app->user->setReturnUrl('/admin/settings');
     return $this->render('index', ['data' => $data]);
 }