public function actionIndex() { $loadedComponents = []; $loadedForSelect = []; $component = ''; $componentSelect = Cms::className(); foreach (\Yii::$app->getComponents(true) as $id => $data) { $loadedComponent = \Yii::$app->get($id); if ($loadedComponent instanceof Component) { $loadedComponents[$loadedComponent->className()] = $loadedComponent; if ($name = $loadedComponent->descriptor->name) { $loadedForSelect[$loadedComponent->className()] = $name; } else { $loadedForSelect[$loadedComponent->className()] = $loadedComponent->className(); } } } if (\Yii::$app->request->get("component")) { $componentSelect = \Yii::$app->request->get("component"); } $component = ArrayHelper::getValue($loadedComponents, $componentSelect); if ($component && $component instanceof Component) { if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { $component->load(\Yii::$app->request->post()); \Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($component); } if (\Yii::$app->request->isAjax) { if ($component->load(\Yii::$app->request->post())) { if ($component->saveDefaultSettings()) { \Yii::$app->getSession()->setFlash('success', 'Успешно сохранено'); } else { \Yii::$app->getSession()->setFlash('error', 'Не удалось сохранить'); } } else { \Yii::$app->getSession()->setFlash('error', 'Не удалось сохранить'); } } } if ($component) { } return $this->render('index', ['loadedComponents' => $loadedComponents, 'loadedForSelect' => $loadedForSelect, 'component' => $component]); }