public function actionPost() { $model = new Wheel(); $modelFeatures = new WheelFeatures(); $modelImages = new Images(); $features = null; if (isset($_POST['submit'])) { $model->attributes = $_POST['Wheel']; $modelImages->attributes = $_POST['Images']; $features = isset($_POST['feature_id']) ? $_POST['feature_id'] : null; $valid = true; $model->user_id = Yii::app()->user->id; // var_dump($model->user_id); //$valid = $valid && $model->validate(); if ($valid) { $data = $_POST['Wheel']; $wheel = WheelApi::addWheel(1, $data); if (!$wheel->hasErrors()) { $features = WheelFeaturesApi::addWheelFeatures($wheel->id, $_POST['feature_id']); $imagePath = ImageUtils::uploadImage($modelImages, 'filename'); if ($features && $imagePath) { $entityId = EntityApi::getIdByType('WHEEL'); $image = ImagesApi::addImage($wheel->id, $entityId, $imagePath); if (!$image) { WheelApi::deleteWheelById($wheel->id); WheelFeaturesApi::deleteAllFeaturesOfWheel($wheel->id); } if (file_exists($imagePath)) { unlink($imagePath); } } else { WheelApi::deleteWheelById($wheel->id); WheelFeaturesApi::deleteAllFeaturesOfWheel($wheel->id); } } } } $this->render('post', array('model' => $model, 'modelFeatures' => $modelFeatures, 'modelImages' => $modelImages, 'features' => $features)); }