General developer forum

Cache problems dynamic theme

Picture of Zarkas Bre del Bor
Cache problems dynamic theme


Maybe you can help me with one problem.

I'm trying to make a multi-domain/instance moodle platform, consisting in a moodle instalation that check the URL and set a theme or a child theme depending on it.

In the moodle/config.php I have defined a function to recover the url and get the subdomain, then depending on it I change the theme ($CFG->theme)

This is my code:

if( function_exists('apache_request_headers') ) {
        $path = apache_request_headers();

        list( $host, $domain ) = explode('.', $path['Host'], 2);

        if ( !empty($CFG->domains[$host]) && $host == 'clientone' ) {
                $CFG->theme = 'themeone';
                $CFG->tempdir = $CFG->dataroot . '/temp/themeone';
                $CFG->localcachedir = $CFG->dataroot . '/localcache/themeone';
                $CFG->cachedir = $CFG->dataroot . '/cache/themeone';
        } else if ( !empty($CFG->domains[$host]) && $host == 'clienttwo' ) {
                $CFG->theme = 'themetwo';
                $CFG->tempdir = $CFG->dataroot . '/temp/themetwo';
                $CFG->localcachedir = $CFG->dataroot . '/localcache/themetwo';
                $CFG->cachedir = $CFG->dataroot . '/cache/themetwo';

This works the first time that I load the page, sometimes not even that, after that theme does not load. 

The log it's empty, and doesn't appear any error.

I have tried to use  $SESSION->theme = 'themeone';

But in the config file does not work ...

I'm a little bit lose with tath.

Any help will be appreciated

Average of ratings: -