/** * Creates a new AdCategory model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new AdCategory(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function compliteAd($modelAdRealEstate) { /* @var $modelAdRealEstate \common\models\AdRealEstate */ $modelAdRealEstate->temp = 1; $transaction = Yii::$app->db->beginTransaction(); try { if ($modelAdRealEstate->save()) { $modelCategory = new AdCategory(); $modelCategory->category = $modelAdRealEstate->property; // Категория для недвижемость 1 $modelCategory->ad_id = $modelAdRealEstate->id; if ($modelCategory->save()) { $modelAdMain = new AdMain(); $modelAdMain->user_id = Yii::$app->user->id; $modelAdMain->place_city_id = $this->place_city_id; $modelAdMain->category_id = $modelCategory->id; $modelAdMain->phone_temp_ad = $this->phone_temp_ad; //$modelAdMain->ad_style_id = 1; if ($modelAdMain->save()) { $transaction->commit(); } } } else { \Yii::$app->session->set('error', 'Объявление недвижимости не добавлено.'); // если все в порядке, пишем в сессию путь к изображениею } } catch (Exception $e) { $transaction->rollBack(); } return $modelAdRealEstate; }