Exemplo n.º 1
0
 /**
  * Creates a new Factencuesta model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     // CONEXION A LA BASE DE DATOS PARA REALIZAR CONSULTAS VIA SQL EN LA DB
     $db = new \yii\db\Connection(['dsn' => 'pgsql:host=localhost;port=5432;dbname=db_sinsch', 'username' => 'nuestroswawas', 'password' => '4358']);
     $db->open();
     $nom_tec = Yii::$app->user->identity->username;
     $tecnico = $db->createCommand('SELECT 
                                     tecnico.id_tecn
                                   FROM 
                                     public."user", 
                                     public.tecnico
                                   WHERE 
                                     "user".username = tecnico.nombre_corto AND 
                                     tecnico.nombre_corto = :nom_tec', [':nom_tec' => $nom_tec])->queryScalar();
     $model = new Factencuesta();
     $model->num_tom = 2;
     $model->fec_ini_tom = '23-07-2015';
     $model->fec_fin_tom = '23-08-2015';
     $model->id_tecn = $tecnico;
     //  $model -> id_tecn = $nom_tec;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['ninio/create', 'id' => $model->id_enc]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }