redirect catre un action indiferent de oriunde in site
  public function beforeAction($action) {
//    U::debug($action->controller->id);
    if (!Yii::$app->user->isGuest) {

      $a = [
        'user/signout',
        'company/create',
        'company/get-details-by-cif'
      ];
      if (!in_array($action->controller->module->requestedRoute, $a, TRUE)) {

        $createCompanyUrl = BaseUrl::base() . '/company/create';
        $currentUrl = BaseUrl::current();
        $user = Yii::$app->user->identity;

        if (!parent::beforeAction($action)) {
          return FALSE;
        }

        if ($createCompanyUrl == $currentUrl) {
          return TRUE;
        }
        else {
          if (empty($user->userCompanies)) {
            Yii::$app->session->setFlash('warning', Yii::t('app', 'In order to use the application you must register at least one company.'));
            Yii::$app->getResponse()->redirect(['company/create']);

            return FALSE; //not run the action

          }
        }
      }
    }
    return TRUE; // continue to run action

  }

About

Das Yii Man

Categories: HINTS (tehnice) |

Leave a Reply

Your email address will not be published. Required fields are marked *

[TOP]