| Current Path : /var/www/html/ebookingdbkl/backend/controllers/ |
| Current File : /var/www/html/ebookingdbkl/backend/controllers/SettingController.php |
<?php
namespace backend\controllers;
use Yii;
use backend\models\Setting;
use backend\models\SettingSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* SettingController implements the CRUD actions for Setting model.
*/
class SettingController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Setting models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new SettingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$model = new \backend\models\Setting;
$post = Yii::$app->request->post();
if(!empty($post)) {
if($model->load($post)) {
foreach($model->value as $key => $val) {
$modelsave = \backend\models\Setting::findOne($key);
$modelsave->value = $val;
$modelsave->save();
}
}
Yii::$app->session->setFlash('success', 'Tetapan Disimpan !!');
}
return $this->render('index', [
'model' => $model,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Setting model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Setting model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Setting();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->setting_id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Setting model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->setting_id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Setting model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Setting model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Setting the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Setting::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}