/** * Creates a new TblUsuario model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new TblUsuario(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new TblFuncionario model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new TblFuncionario(); $modelp = new TblPersona(); $modelu = new SignupForm(); if ($model->load(Yii::$app->request->post()) && $modelp->load(Yii::$app->request->post()) && $modelu->load(Yii::$app->request->post())) { $modelp->imageFile = UploadedFile::getInstance($modelp, 'imageFile'); if ($model->validate() && $modelp->validate()) { $connection = \Yii::$app->db; $transaction = $connection->beginTransaction(); try { $modelp->save(); $dir = md5($modelp->id) . '.png'; $modelp->dir_foto = $dir; $modelp->save(); $modelp->imageFile->saveAs("images/face/" . $dir); $model->id = $modelp->id; $model->antiguedad = 0; $model->estado = 1; $model->item = TblUnidades::getItem($model->id_unidad)->item + 1; $model->save(); //$mo = new SignupForm(); //password,username,email $user = $modelu->signup(); $usuario = new TblUsuario(); $usuario->nom_usuario = $modelu->username; //$usuario->estado=1; $usuario->id = $model->id; $usuario->iduser = $user->id; // $transaction->commit(); $usuario->save(); return $this->redirect(['view', 'id' => $modelp->id]); } catch (Exception $e) { $transaction->rollback(); } } else { //print_r($model); //print_r($modelp); // print_r($modelu); } } return $this->render('create', ['model' => $model, 'modelp' => $modelp, 'modelu' => $modelu]); }