File: /home/safarimaris/home/safarimaris/backend/controllers/SettingController.php
<?php
namespace backend\controllers;
use Yii;
use common\models\Setting;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\caching\TagDependency;
/**
* SettingController implements the CRUD actions for Setting model.
*/
class SettingController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Setting models.
* @return mixed
*/
public function actionIndex()
{
if ($post = Yii::$app->request->post()) {
foreach ($post as $key => $value) {
if ($key != '_csrf-asfm') {
$model = Setting::findOne($key);
$model->value = $value;
$model->save();
}
}
TagDependency::invalidate(Yii::$app->cache, ['index_texts', 'currency']);
return $this->redirect(['index']);
} else {
return $this->render('index', [
'items' => Setting::find()->all(),
]);
}
}
}