/** * Creates a new CsObjects model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new CsObjects(); $model_trans = new CsObjectsTranslation(); if ($objects = Yii::$app->request->get('CsObjects')) { $model->object_id = !empty($objects['object_id']) ? $objects['object_id'] : null; $model->object_type_id = !empty($objects['object_type_id']) ? $objects['object_type_id'] : null; } if ($model->load(Yii::$app->request->post()) and $model_trans->load(Yii::$app->request->post())) { $parent = $this->findModel($model->object_id); $model->level = $parent->level + 1; if ($model->save()) { if ($model->imageFile) { $model->upload(); } $model_trans->object_id = $model->id; $model_trans->orig_name = $model->name; $model_trans->save(); //if($model_trans->save()){ return $this->redirect(['view', 'id' => $model->id]); //} } } else { return $this->render('create', ['model' => $model, 'model_trans' => $model_trans]); } }