We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4230
    • 28 Posts
    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
      • 4230
      • 28 Posts
      Just to let you know that the first issue, the one with the template changes, has been fixed! It was a hard one but I praise the God of Jacob that it works!
      I’ll be working on the second issue next week. Once it’s done I’ll post it here.
      If you are interested in this feature then please let me know, otherwise there is not need for me to share this with others.
      Thank you and may God bless you.
        • 20289
        • 958 Posts
        Iasmin B good explanation!, Topic subject was so interesting to me smiley

        The main issue here is the cache system, it’s just fair for small sites but as much as inputs are going higher the cache issue goes crazy!
        we have had to do the same task for some local news sites under the main super-site but the same issues ran us to do something to the cache system, I may share the thechniques and the codes if i get time sooner than later wink
          [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
          [td][Wiki] [Persian support forum]
          [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
          [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
          • 4230
          • 28 Posts
          Hello MotSmart,
          Thank you for your reply. Yeah, the cache system was a problem. The thing is that I figured out how to do it so that it will work just as if you would have a separate installation of MODx for each site, and it works good with no problems smiley . I praise God for it. It took a while figuring it out but in the end I believe that God gave me the solution, so I praise him for it.
          What I did is that there is a siteCache.idx.php file for each separate domain. Right now this file has to be added manually, which could be changed. So right now, for example, we have ad_siteCache.idx.php and ac_siteCache.idx.php where the database data is stored for that website. This way each website can have it’s own separate configuration; the only problem is that one has to go to that domain’s manager in order to edit it. So it can’t be done from one manager.

          I would like to know what changes you made to the cache system. I’m sure there is a better one than what I did.

          What do you think about sharing content between multiple domains? MODx version 0.9.6 is not built for that right now. Do you have any ideas? I have some but haven’t started to play with them yet.

          Thank you so much and may God bless you all and guide you. Amen.
            • 1611
            • 591 Posts
            Have you seen Subsites the MAD [HACK]?
            What’s the difference between this solution and your one?
              • 4230
              • 28 Posts
              Hello Andrey,
              I’ve never seen that hack before. Thanks for mentioning it.
              Unfortunately it is a little difficult to understand the descriptions and what that hack does but I think that I do get the general idea, at least I hope. I’m going to refer to the "Subsites the MAD [Hack]" as "Subsites" and I’m going to try to compare the hack that we did. I’m going to try to figure this out from the Subsites’ description, since I don’t have time to test it.
              Subsites:
              Pros:
              - Changes only a few files (cache files and config.inc.php).

              Cons:
              - As far as I can see the templates, chuncks, plugins, modules and snippets can’t be shared between multiple websites. They would have to be installed and set up separately.
              - Doesn’t have the ability to share documents without having to copy and paste them in the new sites.
              - As far as I can see there is need for multiple databases for each new site, or at least each table has to have a different prefix (eg. site1_ and site2_).
              - "Moreover, this cannot be used together with other subsites system plugins." I’m not too sure what this means, but seems like a limitation.


              The AmazingDiscoveries.org Multisite hack:
              Pros:
              - We have all the sites hosted in one databases. Only 3 tables are different for each site, because they hold data specific to that specific website.
              - All snippets, chuncks, plugins, templates, documents, etc can be shared between all websites. Although, I still have to work on finding a way to share documents between multiple websites, without duplicating them, but the possibility is there, although the functionality is not implemented yet.

              Cons:
              - At the moment there is a little manual work that needs to be done in order for a new site to be added (domain to be added, config.inc.php page to be changed, add a new cache file and make it writable). But once it is added one has access to all the snippets, chunks, etc as the other websites.
              - The way that MODx core files and each plugin, snippet, and module accesses the database has to be changed from using the MODx $prefix to using the MODx $modx->getFullTableName() method. This requires a lot of files to be changed, although I could share the changed files with the MODx community.


              So far the Subsites hack is only different from the original MODx in that it controls multiple databases (one for each site) from one code source, instead of multiple domains from multiple sources, as MODx version 0.9 works. The AD multisite hack controls multiple websites from the same database from the same source.
                • 1611
                • 591 Posts
                I found one more solution. Subsites/Subdomains
                and [Hack] Subsites.
                As far as I can see this hack allow to share snippets, templates, and other data between sites.

                But it also has some bugs, as wrong links generating when you use [~id~] and, second, it does not correct the domain name in URL, if we links to page of other subsite.
                  • 4230
                  • 28 Posts
                  Hey Andrey,
                  Thanks for sharing those other hacks. Subsites/Subdomains doesn’t seem to help much at all, although maybe the plugin idea could be used further.
                  The [HACK] Subsites one is quite a nice hack though and this might be working nicely. I’m looking at it as we speak.
                    • 4230
                    • 28 Posts
                    Hello there,
                    Quote from: Andrey at Mar 11, 2009, 12:07 PM

                    [Hack] Subsites

                    This hack seems to do a lot of what I tried to implement with my hack. As Andrey said, there are a few problems with the links and domain names. Those are no problems with my hack, but unfortunately there are more changes to be done to the actual core of MODx. Please check this page to see the request and updates (you do need a login though). The changes I requested were applied in MODx Evolution-1.0.0-beta. Maybe I could work on a SVN update for the changes that need to be done to the MODx core files, if anyone would like to use it. But I think that in general people could use the [HACK] Subsites and be fine with it. For us though we require a little more.

                    The other thing is that I’m not sure if the [HACK] Subsites has the ability to share one document in multiple websites without duplicating it and using a template for that website. This is the problem that I’m currently trying to fix and find a solution for.
                      • 22303 MODX Staff
                      • 10,725 Posts
                      There is currently no MODx Evolution-1.0.0-beta release, so I think you mean 0.9.6.3.