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.

Themes

Discuss SilverStripe Themes.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

theme not passed on through $_SESSION


Reply

5 Posts   1771 Views

Avatar
gaston

10 March 2009 at 8:42am Community Member, 24 Posts

Dear All,

I try to have the theme selected in the calling URL via http://localhost/demo/?theme=test01 and the code

if(isset($_GET['theme'])) {
$_SESSION['theme'] = $_GET['theme'];
}

$theme = isset($_SESSION['theme']) ? $_SESSION['theme'] : 'blackcandy';

SSViewer::set_theme($theme);


in _config.php.
The theme is selected correctly but not passed on to the subsequent pages. So when I click "About Us" the theme is reverted back to my default blackcandy. According to the posts in this forum this should not happen ... any ideas?
I am on SS2.3.0

Ciao, Mathias

Avatar
Willr

13 March 2009 at 3:45pm Forum Moderator, 5511 Posts

Try using the build in Session methods. Session::set('theme', 'mytheme'); Session::get('theme') rather then the $_SESSION directly

Avatar
gaston

13 March 2009 at 10:27pm Community Member, 24 Posts

Salut Will,

I tried it and got a strange reaction:
I inserted ONLY the line

Session::set('theme', 'mytheme');

ind

_config.php

and immediately the following error appears when calling the page

Warning: No current controller available in E:\wamp\www\SilverStripe\sapphire\core\control\Controller.php on line 346

Fatal error: Call to a member function getSession() on a non-object in E:\wamp\www\SilverStripe\sapphire\core\Session.php on line 57

I interpreted your suggestion to use this:

Session::set('theme', 'ncse01');
$theme = 'ncse01';
if(isset($_GET['theme'])) {
Session::set('theme', $_GET['theme']);
$theme = $_GET['theme'];
}

SSViewer::set_theme($theme);

but this gives the error above as well. I am quite new to php ...

Ciao, Mathias

Avatar
gaston

19 March 2009 at 1:22am (Last edited: 19 March 2009 1:22am), Community Member, 24 Posts

Salut Will (or others who have access to the source),

could you please publish the _config.php of http://demo.silverstripe.org?

Ciao, Mathias

Avatar
gaston

8 April 2009 at 6:25pm Community Member, 24 Posts

Salut,

just for information: I fixed the issue by setting a cookie that holds the actual theme and reading it back from $_COOKIE in _config.php:

if(isset($_GET['theme'])) {
   $mytheme = $_GET['theme'];
   setcookie("SessionTheme", $mytheme);
} else {
   if (isset($_COOKIE['SessionTheme'])) {
      $mytheme = $_COOKIE['SessionTheme'];
   } else {
      $mytheme = 'blackcandy';
   }
}
SSViewer::set_theme($mytheme);


(I am new to php, so the code can probably be written much nicer)

Ciao, Mathias