Jump to:

23372 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Undefined variable: _SESSION when calling a new method

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 2905 Views
  • TotalNet
    Avatar
    Community Member
    181 Posts

    Undefined variable: _SESSION when calling a new method Link to this post

    Okay, so I've been scratching my head over this one for the last couple of hours now and getting nowhere.

    I've added a method to the Product_Image class to set the image sizes from an array in _config.php which works a treat using default values but as soon as I call the method from _config.php I get the _SESSION error.

    It's nothing to do with the code within the function as I've removed it and it still generates the same error.

    Here's the code in the hope someone can point out what is bound to be an obvious ommission

    _config.php

    Product_Image::set_productImageConfig(array('paddingBgColor' => 'ff0000'));

    product.php

    class Product_Image extends Image {
    ...
    protected static $productImageConfig = array(
    "paddingBgColor" => "ffffff",
    "thumbnailWidth" => "150",
    "thumbnailHeight" => "100",
    "thumbnailQuality" => "80",
    "contentImageWidth" => "150",
    "contentImageQuality" => "90",
    "largeImageWidth" => "500",
    "largeImageQuality" => "90"
    );
    ...
    public static function set_productImageConfig($config) {
    if (is_Array($config)) {
    foreach ($config as $k => $v) {
    if (array_key_exists ($k, self::$productImageConfig) && !is_null($v)) {
    self::$productImageConfig[$k] = $v;
    }
    }
    }
    }
    ...
    }

  • carlos
    Avatar
    Community Member
    41 Posts

    Re: Undefined variable: _SESSION when calling a new method Link to this post

    Hi,

    I've tried you code and it works fine for me, maybe it's something you are doing after assign values to that array.

    cheers

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Undefined variable: _SESSION when calling a new method Link to this post

    Thanks Carlos

    Well, if I put the site into "Live" mode then the site displays and the function itself works but I can't log in - the _SESSION error is still present in the background.

    I tried moving the code to the Product class making the static pulic and referencing it directly from the image class but that made no difference.

    I have now moved the code to a new class (and .php file in mysite/code) and that's working now but, I wanted to get it working in the Procuct_Image class with the hope that it would make it in there officially.

    Is this error caused by some formatting problem with the file itself perhaps? Maybe PhpED has screwed up the encoding or something?

    Cheers,

    Rich

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Undefined variable: _SESSION when calling a new method Link to this post

    This is getting frustrating now

    Getting the same error just trying to add a decorator, tried a simple one first, just decorating the Page class with the same result as soon as I add DataObject::add_extension to _config.php.

    Trouble is, this error doesn't give me any idea where to start looking for issues, is it an environmental thing? is there one file with an issue that only shows under certain conditions?

    If anyone has ideas on where to start looking I'd appreciate it, in the mean time I'll try another installation, v2.3.4 perhaps.

    Cheers,

    Rich

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Undefined variable: _SESSION when calling a new method Link to this post

    Thought I had a solution there for a minute, but no. can't delete my post.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Undefined variable: _SESSION when calling a new method Link to this post

    This is often caused by whitespace after a closing PHP tag. Do you have a closing PHP tag in Product.php, and does it have whitespace after it? If so, that could cause the issue. I would reccomend removing all closing tags from your site code since they're optional anyway and can cause issues like this which are hard to diagnose.

  • TotalNet
    Avatar
    Community Member
    181 Posts

    Re: Undefined variable: _SESSION when calling a new method Link to this post

    Thanks for the reply, I'd read that in one of the other threads about this error and have checked where ever I could.

    It's now fixed though, for now ;)
    I comapred with an environment that worked and it seems there was something about my page.php it didn't like, no idea what but it's behaving properly now so I'm happy.

    Cheers,

    Rich

  • smix
    Avatar
    Community Member
    1 Post

    Re: Undefined variable: _SESSION when calling a new method Link to this post

    I also had this problem and the cause was the encoding of the _config.php file. I had it set to UTF8 encoding (using Notepad++), when I changed it back to ANSI this error disappeared!

    2905 Views
Page: 1 2
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.