backend/controllers/CompaniesController.php
/**
     * Creates a new Companies model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Companies model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
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())) {
                $imageName = $model->company_name;
                if(!empty($model->file)){
                    $model->file = UploadedFile::getInstance($model, 'file');
                    $model->file->saveAs('uploads/'.$imageName.'.'.$model->file->extension);
                    $model->logo = 'uploads/'.$imageName.'.'.$model->file->extension; 
                }
                $model->company_created_date=date('Y-m-d h:m:s');
                $model->save();
                $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;
        }
    }
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 ; if ( ! empty ( $ model -> file ) ) { $ model -> file = UploadedFile :: getInstance ( $ model , 'file' ) ; $ model -> file -> saveAs ( 'uploads/' . $ imageName . '.' . $ model -> file -> extension ) ; $ model -> logo = 'uploads/' . $ imageName . '.' . $ model -> file -> extension ; } $ model -> company_created_date = date ( 'Y-m-d h:m:s' ) ; $ model -> save ( ) ; $ 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.
Creates a new Companies model .
// get the instance of the uploaded file // save the path in the db column