We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17895
    • 209 Posts
    Good evening to everybody,
    I am trying to use contexts (I am trying to use the Babel package), but I cannot visualize, in the frontend, any page that are in the other context (I have two contexts: web and webit, I see pages from web, but not from webit).

    I mean that I am using the q= GET parameter in the URL, with the id of the URL. When I move the same page in the web context, I can see it, if I move in the webit context, the browser is pointed to the homepage (of the web context).

    What am I doing wrong?
      Daniele "MadMage" Calisi
      • 22303 MODX Staff
      • 10,725 Posts
      How are you routing requests to the appropriate Context?
        • 17895
        • 209 Posts
        Quote from: OpenGeek at Jan 17, 2011, 07:50 AM

        How are you routing requests to the appropriate Context?

        This questions make me understand that I do not know enough about contexts. I followed the guide here: http://rtfm.modx.com/display/revolution20/Creating+a+Subdomain+from+a+Folder+using+Virtual+Hosts , trying to figure out how contexts work (not successfully, it seems).

        When you say "routing", do you mean something related to this: http://rtfm.modx.com/display/revolution20/Using+One+Gateway+Plugin+to+Manage+Multiple+Domains ? I.e., do I always need a gateway plugin? in the previous page this is not needed (or it is not said).

        As far as I can understand, I need a switchContext() call somewhere (in the gateway plugin). It is right? If so, why there is no mention of that in the previous page? If not, what do you mean with "routing requests" ?

        Thanks!

        P.S.: I cannot understand why in the second page they use getOption() to understand the requested URL... shouldn’t "getOption" be used AFTER switching context (i.e., the http_host is different in different contexts, so the "true" value is available AFTER the switchContext).

        P.P.S.: is there any additional page about contexts, not in the RTFM?
          Daniele "MadMage" Calisi
          • 22303 MODX Staff
          • 10,725 Posts
          There are different methods being discussed in those links—one uses virtual hosts to route requests to index.php files that initialize the context associated with that virtual host (IOW Apache handles the routing of the virtual host to the proper context); the second uses a plugin to detect the hostname and switches contexts based on whatever logic you put in your "gateway" plugin.
            • 17895
            • 209 Posts
            Quote from: OpenGeek at Jan 17, 2011, 10:06 AM

            There are different methods being discussed in those links—one uses virtual hosts to route requests to index.php files that initialize the context associated with that virtual host (IOW Apache handles the routing of the virtual host to the proper context); the second uses a plugin to detect the hostname and switches contexts based on whatever logic you put in your "gateway" plugin.

            OK thanks for the reply.

            However: I do not understand why the $modx->getOption(’http_host’) returns the host used in the URL request, rather than the http_host configuration item of the current context (or general configuration options if default context or not http_host is not overridden by the context).
              Daniele "MadMage" Calisi
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: MadMage at Jan 17, 2011, 10:21 AM

              However: I do not understand why the $modx->getOption(’http_host’) returns the host used in the URL request, rather than the http_host configuration item of the current context (or general configuration options if default context or not http_host is not overridden by the context).
              That is the whole point. When the request is being processed, the example gateway plugin uses the HTTP_HOST requested by the client to determine which context to load. Once the context is loaded, then the configuration in the context takes over. You have to have some way of determining which context to load based on some part of the request being made. The virtual host alternative does the same thing—it just allows Apache’s virtual host mechanism to determine which directory to look at (and thus which index.php with a specific context initialization to use) based on the HTTP_HOST requested by the client.
                • 17895
                • 209 Posts
                Quote from: OpenGeek at Jan 17, 2011, 12:24 PM

                That is the whole point. When the request is being processed, the example gateway plugin uses the HTTP_HOST requested by the client to determine which context to load. Once the context is loaded, then the configuration in the context takes over. You have to have some way of determining which context to load based on some part of the request being made. The virtual host alternative does the same thing—it just allows Apache’s virtual host mechanism to determine which directory to look at (and thus which index.php with a specific context initialization to use) based on the HTTP_HOST requested by the client.

                Ok, I understand all this. I am only confused about the use of $modx->getOption(’http_host’), since, AFAIK, $modx->getOption() function gets system settings, i.e., the things that are saved in Tools/System Settings in the manager, is it right? it is not the request by the client. Or is ’http_host’ getOption different? what if I put a ’http_host’ setting in System Settings? is there a list of other "options" that one can retrieve with getOption() ?

                Thanks a lot! smiley
                  Daniele "MadMage" Calisi
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: MadMage at Jan 18, 2011, 02:48 AM

                  Quote from: OpenGeek at Jan 17, 2011, 12:24 PM

                  That is the whole point. When the request is being processed, the example gateway plugin uses the HTTP_HOST requested by the client to determine which context to load. Once the context is loaded, then the configuration in the context takes over. You have to have some way of determining which context to load based on some part of the request being made. The virtual host alternative does the same thing—it just allows Apache’s virtual host mechanism to determine which directory to look at (and thus which index.php with a specific context initialization to use) based on the HTTP_HOST requested by the client.

                  Ok, I understand all this. I am only confused about the use of $modx->getOption(’http_host’), since, AFAIK, $modx->getOption() function gets system settings, i.e., the things that are saved in Tools/System Settings in the manager, is it right? it is not the request by the client. Or is ’http_host’ getOption different? what if I put a ’http_host’ setting in System Settings? is there a list of other "options" that one can retrieve with getOption() ?

                  Thanks a lot! smiley
                  Using the separate virtual hosts approach, once the initialize() is called with a specific context and the configuration is loaded then getOption(’http_host’) will return what you set in the system/context settings, but before initialize() is called. If using the plugin OnHandleRequest to switch contexts, then http_host would be overridden if you set a system setting (or context setting for the initial context, usually web) for http_host specifically, and in that case, you would not be able to do this unless you looked directly at $_SERVER[’HTTP_HOST’].
                    • 17895
                    • 209 Posts
                    Quote from: OpenGeek at Jan 18, 2011, 10:50 AM

                    Using the separate virtual hosts approach, once the initialize() is called with a specific context and the configuration is loaded then getOption(’http_host’) will return what you set in the system/context settings, but before initialize() is called. If using the plugin OnHandleRequest to switch contexts, then http_host would be overridden if you set a system setting (or context setting for the initial context, usually web) for http_host specifically, and in that case, you would not be able to do this unless you looked directly at $_SERVER[’HTTP_HOST’].

                    :-O... that’s it... it was under my eyes... thanks!
                      Daniele "MadMage" Calisi