public function addSupplier() { if ($this->validate()) { $supplier = new Supplier(); $supplier->name = $this->name; $supplier->save(); } }
/** * Creates a new EntpSupplier model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Supplier(); if ($model->load(Yii::$app->request->post())) { // $x = Yii::$app->request->post(); // $me = $x['Supplier']['entrepreneur']; $model->loadDefaultValues(); $model->save(); if ($model->save()) { $supplier = new EntpSupplier(); $supplier->entrepreneur_user_id = Yii::$app->user->id; $supplier->link('supplier', $model); } Yii::$app->session->setFlash('success', 'Create New Supplier Success'); return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Supplier model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Supplier(); if ($model->load(Yii::$app->request->post())) { $model->loadDefaultValues(); $model->save(); if ($model->save()) { $ensup = new EntpSupplier(); $ensup->supplier_id = $this->id; $ensup->entrepreneur_id = Yii::$app->user->id; $ensup->link('supplier', $model); } Yii::$app->session->setFlash('success', 'ok'); $searchModel = new EntpSupplierSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); //return $this->redirect(['view', 'id' => $model->id, 'profile_user_id' => $model->profile_user_id]); } else { return $this->render('create', ['model' => $model]); } }