View Snippet #221

    
  namespace app\components;
   
  use yii\web\UrlManager;
  use Yii;
   
  class XUrlManager extends UrlManager
  {
      public function createXUrl($params = [])
      {
          $params =(array) $params;
          // make sure we have all the data
          if (isset(Yii::$app->params['organization_id']) && isset(Yii::$app->params['organization_name']))
          {
              // grab the requested route
              $route=$params[0];
              // add on the bits we want org_name/org_id
              $route=Yii::$app->params['organization_name']."/".Yii::$app->params['organization_id']."/".$route;
              // put the new route back into array
              $params[0]=$route;
              // just in case, get rid of org_id from parameters in url eg: controller/action?orgid=x
              if (array_key_exists('orgid',$params))
              {
                  unset($params['orgid']);
              }
          }
          // call the regular urlManager
          $urlManager = Yii::$app->urlManager;
          return $urlManager->createUrl($params);
      }
  }