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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Themes /

Discuss SilverStripe Themes.

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

theme not passed on through $_SESSION


Go to End


5 Posts   2366 Views

Avatar
gaston

Community Member, 26 Posts

10 March 2009 at 8:42am

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

Forum Moderator, 5523 Posts

13 March 2009 at 3:45pm

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

Avatar
gaston

Community Member, 26 Posts

13 March 2009 at 10:27pm

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

Community Member, 26 Posts

19 March 2009 at 1:22am

Edited: 19/03/2009 1:22am

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

Community Member, 26 Posts

8 April 2009 at 6:25pm

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