Jump to:

1382 Posts in 491 Topics by 521 members

Themes

SilverStripe Forums » Themes » theme not passed on through $_SESSION

Discuss SilverStripe Themes.

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

Page: 1
Go to End
Author Topic: 1751 Views
  • gaston
    Avatar
    Community Member
    24 Posts

    theme not passed on through $_SESSION Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: theme not passed on through $_SESSION Link to this post

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

  • gaston
    Avatar
    Community Member
    24 Posts

    Re: theme not passed on through $_SESSION Link to this post

    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

  • gaston
    Avatar
    Community Member
    24 Posts

    Re: theme not passed on through $_SESSION Link to this post

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

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

    Ciao, Mathias

  • gaston
    Avatar
    Community Member
    24 Posts

    Re: theme not passed on through $_SESSION Link to this post

    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

    1751 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.