How are you routing requests to the appropriate Context?
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.
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.
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.
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’].
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!
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’].