/**
  * 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')) {
         $company = new Companies();
         $branch = new Branches();
         if ($company->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) {
             // print_r($company);
             // print_r($branch);
             // die;
             // get the instance of the uploaded file
             $imageName = $company->company_name;
             $company->file = UploadedFile::getInstance($company, 'file');
             $company->file->saveAs('uploads/' . $imageName . '.' . $company->file->extension);
             // save the path in the db column
             $company->logo = 'uploads/' . $imageName . '.' . $company->file->extension;
             $company->company_created_date = date('Y-m-d h:i:s a');
             $company->save();
             // save branches
             $branch->branch_created_date = date('Y-m-d h:i:s a');
             $branch->save();
             return $this->redirect(['view', 'id' => $company->company_id]);
         } else {
             return $this->render('create', ['company' => $company, 'branch' => $branch]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
 /**
  * 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())) {
             // get the instance of the uploaded file
             $imageName = $model->company_name;
             if (!empty($model->file)) {
                 $model->file = UploadedFile::getInstance($model, 'file');
                 $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
                 // save the path in the db column
                 $model->logo = 'uploads/' . $imageName . '.' . $model->file->extension;
             }
             $model->company_created_date = date('Y-m-d h:m:s');
             $model->save();
             // save the branch
             $branch->companies_company_id = $model->company_id;
             $branch->branch_created_date = date('Y-m-d h:m:s');
             $branch->save();
             return $this->redirect(['view', 'id' => $model->company_id]);
         } else {
             return $this->render('create', ['model' => $model, 'branch' => $branch]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
 /**
  * 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();
     }
 }
 /**
  * Creates a new Companies model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  * 1、上传文件
  * 2、将company表单和branch表单放一起
  */
 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())) {
             //文件上传
             $imageName = $model->company_name;
             $model->file = UploadedFile::getInstance($model, 'file');
             $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
             //保存路径到数据库
             $model->logo = 'uploads/' . $imageName . '.' . $model->file->extension;
             $model->save();
             //保存branch
             $branch->companies_company_id = $model->company_id;
             $branch->save();
             return $this->redirect(['view', 'id' => $model->company_id]);
         } else {
             return $this->render('create', ['model' => $model, 'branch' => $branch]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
 /**
  * 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();
     $branch = new Branches();
     if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) {
         if (!empty($model->file)) {
             // get the instance of the uploaded file
             $imageName = date('Ymdhis');
             $model->file = UploadedFile::getInstance($model, 'file');
             $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
             //save image name to db
             $model->logo = $imageName . '.' . $model->file->extension;
         }
         $model->company_created_date = date('Y-m-d h:i:s');
         if ($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]);
     }
 }
Beispiel #7
0
 /**
  * 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();
     $branch = new Branches();
     if (Yii::$app->user->can('create-company')) {
         if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) {
             $imageName = $model->company_name;
             $model->file = UploadedFile::getInstance($model, 'file');
             if ($model->file) {
                 $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
                 $model->logo = 'uploads/' . $imageName . '.' . $model->file->extension;
             }
             $model->save();
             $branch->companies_company_id = $model->company_id;
             $branch->branch_created_date = date('Y-m-d');
             $branch->save();
             return $this->redirect(['view', 'id' => $model->company_id]);
         } else {
             return $this->render('create', ['model' => $model, 'branch' => $branch]);
         }
     } else {
         return $this->redirect(['index']);
     }
 }