Ejemplo n.º 1
0
 public function actionSettings()
 {
     $languages = Languages::find()->select(['url', 'name'])->all();
     $model = new SettingsForm();
     $model->frontend_default_language = Languages::getDefaultLanguage()->url;
     $model->setAttributes(ArrayHelper::map(Settings::find()->all(), 'name', 'value'));
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         foreach ($model->attributes as $key => $value) {
             Settings::updateAll(['value' => (string) $value], '`name` = :key', [':key' => $key]);
         }
         Languages::setDefaultLanguage($model->frontend_default_language);
         Yii::$app->getSession()->setFlash('success', Yii::t('main', 'Settings successfully saved'));
     }
     return $this->render('settings', ['model' => $model, 'languages' => $languages]);
 }
Ejemplo n.º 2
0
 protected function resolveRequestUri()
 {
     $selected = Settings::findOne('backend_language')->value;
     Languages::setCurrent($selected ? $selected : Languages::getDefaultLanguage()->url);
     return parent::resolveRequestUri();
 }