public function actionCreate() { $app = $this->getApp(); $model = new Elements(); $model->app_id = $app->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('backend', 'Элемент создан. Необходимо его настроить.')); return $this->redirect(['update', 'app' => $app->id, 'element' => $model->id]); } return $this->render('create', ['app' => $app, 'model' => $model]); }
public function afterSave($insert, $changedAttributes) { if ($insert) { $this->create(); $elements = (require Yii::getAlias('@worstinme/zoo/applications/default/Elements.php')); if (is_array($elements) && count($elements)) { foreach ($elements as $key => $params) { $element = new Elements(); $element->setAttributes($params); $element->name = $key; $element->app_id = $this->id; $element->allcategories = 1; if (!$element->save()) { print_R($element->errors); } } } } return parent::afterSave($insert, $changedAttributes); }