mirror of
https://github.com/CyanoFresh/SmartHomePHP.git
synced 2026-03-06 09:56:49 +01:00
Refactor; Added settings
This commit is contained in:
39
modules/admin/controllers/SettingController.php
Normal file
39
modules/admin/controllers/SettingController.php
Normal 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']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user