public function actionEdit($id = null) { $model = new DynamicContent(); $model->loadDefaultValues(); if ($id !== null) { $model = DynamicContent::findOne($id); } $static_values_properties = []; if (isset($_GET['DynamicContent'])) { if (isset($_GET['DynamicContent']['object_id'])) { $model->object_id = intval($_GET['DynamicContent']['object_id']); } } $property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where([])->column(); $properties = Property::find()->where(['has_static_values' => 1, 'has_slugs_in_values' => 1])->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all(); foreach ($properties as $prop) { $static_values_properties[$prop->id] = ['has_static_values' => true, 'property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id)]; } $post = \Yii::$app->request->post(); if (isset($_GET['DynamicContent'])) { $post = $_GET; } if ($model->load($post) && $model->validate() && !isset($_GET['DynamicContent'])) { $save_result = $model->save(); if ($save_result) { return $this->redirectUser($model->id); } else { \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data')); } } return $this->render('dynamic-content-form', ['model' => $model, 'static_values_properties' => $static_values_properties]); }
/** * Finds model by id using identity map * @param $id * @return mixed */ public static function findById($id) { if (!isset(static::$identity_map[$id])) { static::$identity_map[$id] = DynamicContent::findOne($id); } return static::$identity_map[$id]; }