/** * Lists all Settings models. * @return mixed */ public function actionIndex() { if (Yii::$app->request->post()) { $section = Yii::$app->request->post(); foreach ($section as $key => $item) { if (count($item) > 1 || is_array($item)) { // $modal = new Settings(); // $setting_item = $modal->findOne(['key' => $key]); $value = $item['value']; if (!isset($item['value']) && $item['type'] === 'boolean') { $value = !isset($item['value']) ? '0' : '1'; } if (!isset($item['value']) && $item['type'] === 'integer') { $value = isset($item['value']) ? (int) $item['value'] : 0; } // $setting_item->value = $value; // $setting_item->active = $item['active']; if (Settings::updateAll(['value' => $value, 'active' => $item['active']], ['key' => $key])) { echo "Success"; /* if($success < 0) { echo Alert::widget([ 'type' => 'success', 'options' => [ 'title' => 'Success message', 'text' => "You will not be able to recover this imaginary file!", 'confirmButtonText' => "Yes, delete it!", 'cancelButtonText' => "No, cancel plx!" ] ]); Yii::$app->session->setFlash('success', 'Настройки сохранены'); echo 'Success'; // данные в базу добавлены, можна и флеш-сообщение показать: }*/ //continue; } else { echo 'Error'; } } } } else { $searchModel = new SettingsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } }