/** * Creates a new Cellars model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Cellars(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Cellars model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Cellars(); //On create, default the owner_id to current user $model->owner_id = \Yii::$app->user->identity->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { $cellarUser = new Cellarusers(); $cellarUser->cellar_id = $model->id; $cellarUser->user_id = \Yii::$app->user->identity->id; $cellarUser->permission = 'OWNER'; if ($cellarUser->save()) { return $this->redirect(['index']); } } else { return $this->render('create', ['model' => $model]); } }