Hello there,
I looked around but found nothing that covered this beside the new MODx Revolution, which is a little too far away.
I work for a non-profit organization called
Amazing Discoveries which has multiple smaller websites. We started to use MODx and we praise God for it and thank you very much for it! Over half a year ago, a friend of mine and I started to work on changing MODx 0.9.6 so that we could manage multiple domain names. After lots of work we finally got it functioning, but there are some issues: thus the purpose of this email.
A few months after we got it running we found out that the MODx team will release the Revolution version of MODx which will have the ability to control and run multiple websites from the same database and manager. That is great but it seems like the progress is really slow so I want to start this topic so that I can get some help in how to solve the current issues.
I have seen quite a few people who wanted something like this and at one point I can share it but I have to solve these issues, so that people won’t run into the same problems.
A few things that had to be changed in order to get this working:
- At that time we encountered a problem where the $modx->getFullTableName() method was not used everywhere but that a lot of code used this instead: $modx->db->config[’table_prefix’] before the table name. I submitted this issue to the MODx developers so that it would be fixed by using the $modx->getFullTableName() everywhere, and they said that it was solved. I just downloaded the newest MODx version and sadly the changes have not been made. This is very important because, the way we figured out to get this multiple domain control to work, uses that method to decide which settings are applied to which domain. Without it this won’t work.
- Another problem that we encountered was with the cache system. When a document/category is created/edited/deleted/moved/etc MODx has a function which recreates the cache files. But when managing another domain, which had to have it’s own cache files because of the settings, those were not reset properly. So a core MODx file had to be changed to bring that about.
- In order to control multiple websites we had to create folders in the root menu tree that resemble each particular domain name. For example: "Amazing Discoveries (1)" and "Rekindling the Reformation (2)". Afterwards we had to create all the documents, or move the already existing ones, to the proper category which acted as a domain. This meant that the site_start setting had to be changed for each domain name to represent that category, id 1 for "Amazing Discoveries" and id 2 for "Rekindling the Reformation." The this site_start was used to generate the menus with the Wayfinder snippet.
- A few of the database tables had to be set to function only for a certain site. The following tables were to be duplicated for each domain name: "system_settings", "active_users" and "event_log". The $modx->getFullTableName() method was used take the right table for the right domain name. For an example these tables were renamed from "modx_system_settings" to "ad_system_settings" and "rtr_system_settings".
You can see the fully working websites here:
http://amazingdiscoveries.org/ and one of the other managed domains is
http://rekindlingthereformation.com/
Now back to the issues that still exist.
- So far the controlling of multiple domains works well but the problem comes when one wants to share some documents between the domains. MODx has a nice feature which is very useful but in this case it proves to be a problem. This feature is that each document can have a template assigned to it. The only way around this right now, as far as I can see, without making any core code changes is to duplicate the document, and this is not a nice option. This is where I could use your ideas, if you have any. So far I figured that a plugin could be written to change the template of the document according to the domain name; but the problem is knowing which template to change it to. I really don’t like working with the TV’s, to me in most cases they only make things harder (but maybe I haven’t learned to work with them properly...), so the other way that I figured out to do it is by following a template naming convention: ie. having the templates "AD-01 Home" (where AD is for the domain, -01 is for the template version and Home is for categorizing where the template is used) and "AD-01 Blog" with the parallel templates for the second domain "RtR-01 Home" and "RtR-02 Blog." Then when the plugin detects that the template naming convention doesn’t match the current domain name it will try to see if a matching template name is found for that domain. Please let me know what you think and if you have a better idea.
- Once the template issue is solved, then we run into a second issue: how to share the documents. I don’t know if you are familiar with ZenCart but they use a Linking functionality to share products among different categories. It is just a second db table which relates products to multiple categories, but the coding is a pest sometimes. I was thinking of trying to do something like this with MODx but if there is a better way please let me know.
Sorry for the length of this message but hopefully it all made sense. I really hope that you could help me with some ideas or directions, and thank you in advance.
May God bless you and may His love and peace fill you.
Amen