public function actionUpdate()
 {
     $app = $this->getApp();
     if (($model = Elements::findOne(Yii::$app->request->get('element'))) === null) {
         Yii::$app->getSession()->setFlash('success', Yii::t('backend', 'Элемент не найден'));
         return $this->redirect(['index', 'app' => $app->id]);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', Yii::t('backend', 'Настройка элемента сохранены'));
         return $this->redirect(['index', 'app' => $app->id]);
     }
     return $this->render('update', ['app' => $app, 'model' => $model]);
 }
Example #2
0
 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);
 }