Example #1
0
 /**
  * @inheritdoc
  */
 public function selEmpresa($action)
 {
     $empresas = \common\models\Osempresas::getEmpresas();
     if (count($empresas) < 1) {
         Yii::$app->session->setFlash('danger', Yii::t('app', 'No access to companies or not created'));
         Yii::$app->session->removeFlash('SelEmpresa');
         return $action->controller->goHome();
     }
     if (count($empresas) == 1) {
         $user = Yii::$app->user->getidentity();
         $user->setEmpresa(key($empresas));
         $user->save();
         Yii::$app->session->removeFlash('SelEmpresa');
         Yii::$app->session->setFlash('warning', Yii::t('app', 'Only one company found'));
         return true;
     }
     Yii::$app->session->setFlash('SelEmpresa', true);
     //return Yii::$app->getResponse()->redirect('site/sel-empresa');
     return $action->controller->goHome();
 }
 /**
  * Finds the Osempresas model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Osempresas the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Osempresas::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }