/**
  * Creates a new Colaborador model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('admin') || Yii::$app->user->can('staff')) {
         $model = new Colaborador();
         if (Yii::$app->request->isAjax && $model->load($_POST)) {
             Yii::$app->response->format = 'json';
             return \yii\widgets\ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post())) {
             $user = new Users();
             $user->usertype = 'Colaborador';
             $user->password = strtolower($model->apellido1 . substr($model->rut, 5, -2));
             $user->email = $model->correo;
             $model->fechaIngreso = date("Y-m-d H:i:s");
             $model->save();
             $user->id_orig = $model->id;
             $user->username = $model->nombre;
             $user->save();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
 /**
  * Creates a new Colaborador model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Colaborador();
     if (Yii::$app->request->isAjax && $model->load($_POST)) {
         Yii::$app->response->format = 'json';
         return \yii\widgets\ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }