Refactor; Added settings

This commit is contained in:
Alex Solomaha
2017-01-02 02:20:27 +02:00
parent c532ccf1be
commit 1e3dc0a7db
22 changed files with 308 additions and 24 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace app\modules\admin\controllers;
use app\models\Setting;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
class SettingController extends Controller
{
public function actionIndex()
{
$models = Setting::find()->all();
return $this->render('index', [
'models' => $models,
]);
}
public function actionSave()
{
$settings = Yii::$app->request->post('Settings');
foreach ($settings as $key => $value) {
$model = Setting::findOne(['key' => $key]);
if (!$model) {
throw new NotFoundHttpException();
}
$model->value = $value;
$model->save();
}
return $this->redirect(['index']);
}
}