/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Companies(); if ($model->load(Yii::$app->request->post())) { $model->company_created_date = date('yyyy-m-d- h:m:s'); $model->save(); return $this->redirect(['view', 'id' => $model->company_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('create-company')) { $model = new Companies(); $branch = new Branches(); if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) { $model->company_created_date = date('Y-m-d H:i:s'); $model->save(); $branch->companies_company_id = $model->company_id; $branch->branch_created_date = date('Y-m-d H:i:s'); $branch->save(); return $this->redirect(['view', 'id' => $model->company_id]); } else { return $this->render('create', ['model' => $model, 'branch' => $branch]); } } else { throw new ForbiddenHttpException(); } }