Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Try to understand the background of the subsites module

Go to End

11 Posts   7105 Views


Community Member, 19 Posts

21 July 2008 at 9:18pm

Hi everybody,

can someone give me a little explanation of the logic behind the subsites module!?

How will the content put into each subsite?

How will the url control the access to each subsite?

Where are the subsites stored physically?

Thank you all.



Administrator, 685 Posts

22 July 2008 at 12:06am

Hi Carnal,

The subsites module changes the database in a few ways:

* Adds a Subsite table
* Adds a SubsiteID to the Group, File and SiteTree table.

Each of the latter tables can therefore hold multiple sub-sites. The URL-uniqueness checker, for example, is updated to only check for unique URLs in a single subsite.

The SiteTree content with SubsiteID = 0 is considered to be the 'default subsite'. Groups and Files with SubsiteID = 0 are considered to be accessible by all subsites.

To create subsites, you should use the Subsites section of the CMS; it's a new main menu item that appears. If you give it a Subdomain, then you can access it. If you're working on a local development environment, a good thing to do is to set up some aliases in your /etc/hosts file so that you can access your local development environment with multiple aliases:

localhost -> default site
something.localhost -> site with Subsite.Subdomain = 'something'
other.localhost -> site with Subsite.Subdomain = 'other'

Within the CMS, a dropdown appears in the top-right, once you have more than one subsite. Use this to switch between subsites. The content, group, or file tree will update accordingly.


Community Member, 19 Posts

22 July 2008 at 2:25am

Edited: 22/07/2008 2:26am

Hi Sam,

thanks for the info - now i know how it should work - but it do not at my installation.
I don't know if you are in the mood to help me with a trunk-module, but this module would be very important for me to use.

I have three problems:

(1) After uploading the module, the installation is not accessible. After i commented these two lines in _config.php i can run "db/build?flush=1" and one Table "subsite" are created (should be another one created: "subsite_templates"?!).

(2) I cannot choose a template at the "add-subsite-dialog"

(3) I have to create the subsites manually in the db, because i get the error: Fatal error: Call to a member function createInstance() on a non-object

(4) I don't get the dropdown at the top-right to select the created subsites.

Thats all for now, hope to get info on this.




Administrator, 685 Posts

22 July 2008 at 9:53am

Hi Carnal,

Try manually going into the database, and adding an entry in the Subsite table with ClassName = 'Subsite_Template'. This might fix the issue.


Community Member, 19 Posts

22 July 2008 at 7:28pm

Edited: 22/07/2008 7:29pm

Hi Sam,

i have done this, now i can add subsites to silverstripe with no error message! Great.
Now i have "just" another question, hope you don't mind ;-)

You wrote:
Within the CMS, a dropdown appears in the top-right, once you have more than one subsite. Use this to switch between subsites. The content, group, or file tree will update accordingly.

I don't get this dropdown, how can i fix this?! Because i have to switch between the sites to add pages etc. Maby i can call the urls manually?!

Thanks again.



Community Member, 19 Posts

25 July 2008 at 12:56am

Hi all,

me again ;-)

Has somebody a little hint about accessing the urls to each subsite in the Admin!?




Community Member, 2 Posts

3 August 2008 at 12:28am

Edited: 03/08/2008 11:16pm

Ok, searched this forum and Google from the back to the front on how to get this usefull module working.

For now, after getting the SVN trunk of subsite to the root directory of my Silverstripe installation i get the same error over and over again when i try to run /db/build?flush=1:

Fatal error: DataObject::buildSQL: Can't find data classes (classes linked to tables) for Subsite in /var/www/vhosts/ on line 1430

I tried the hack of Carnal mentioned in his post at and commented some lines out in the _config.php
Greatfully the /db/build worked after applying his hack, but i got the feeling that the module doesn't install properly, isn't it? For example there are no changes made by the build process to the table Groups.

So i ended up now with a big ? What do i have to do, to get the module installed properly on my Silverstripe 2.2.2 (a question i've read from quite a people on this forum :-)) ??? Any helping hand?

For the record, i also found this post of Racc, which seems to have installed the module without any problems at all... how??

[edit 15:26] Ok, found out that only the Object::add_extension('Group', 'GroupSubsites'); has to be commented out to get /db/build giving a positive result, so there should be the problem for me, anyone any idea where to look for?

[edit 15:54] Well, added the column SubsiteID (int(11), not null default '0') to the table "groups" manually and added an index to it. Now i can remove the comment for Object::add_extension('Group', 'GroupSubsites'); and call the website without any errors.
After entering the CMS i can't find the "subsites"-menu tab, so up to the next issue :-) Any input on this one?

[edit 03-08-08] After i searched for something like a rights problem i discovered that the daily build of Silverstripe had a bug concerning setting rights to groups (rights are set to groupID=0 instead of groupID= id group editted) i installed the latest stable download from the website, did the things above to get Subsites running and voila, "Sub-sites" appears into the CMS menu :-) Can some explain how to assign templates to individual subsites?

After i added a new subsite (my first), silverstripe crashes with an error:

FATAL ERROR: DataObject::get_by_id passed a non-numeric ID #
At line 1669 in /var/www/vhosts/
user_error(DataObject::get_by_id passed a non-numeric ID #,512)
line 1669 of DataObject.php
line 101 of SubsiteAdmin.php
line 238 of Controller.php
line 104 of Director.php
line 158 of main.php
Debug (Debug::showError() in line 180 of Debug.php)
* callerClass =
* id =
Fatal error: Call to a member function createInstance() on a non-object in /var/www/vhosts/ on line 113

Great, but after adding manually a record to Subsite like Sam discribed above, i'm able to successfully add more subsites and templates :-) But, now the dropdown at the top right is missing, needed to switch the trees for the different subsites. I discovered that ?flush=1 or manually deleting the cache content located in /tmp does miracles, and in this case it did, the dropdown shows up :-)

I'm curious how to add different templates to the different subsites. The definition of "Template" within the module configuration is another one than "template" as the visualisation of your website, it's only a way to quickly create subsites from default settings.

Sam and other users, how do i set the allowed_themes and allowed_domains for the module?


Community Member, 63 Posts

8 August 2008 at 6:43am

This is how we did it...

we added this in the controller of mysite/page.php

if ($this->SubsiteID) {
            $subsite = DataObject::get_by_id("Subsite", $this->SubsiteID);

and this in mysite/_config.php

//Set the available sub site themes like so 
Subsite::set_allowed_themes(array('theme1', 'theme2'));

theme1 and theme2 corresponding to theme folders with the same name.. Adding to this array, while adding new themes gives you the ability to change themes from the subsite admin menu.

Go to Top